|
Override it all
Last post 03-20-2008 5:31 AM by RayS. 11 replies.
-
03-19-2008 2:50 AM
|
|
-
KIMOSABI


- Joined on 03-19-2008
- Posts 1
|
Help! Save me from this place!!! :(
This is one small example of our senior architect's deep understanding of OO principles! Public Overrides Property ID() As String Get Return
MyBase.ID End Get Set(ByVal value As String) MyBase.ID = value End
Set End Property
|
|
-
-
TGV


- Joined on 10-09-2005
- Posts 90
|
Ok, it looks pretty superfluous, almost enterprisey, but as a general principle shielding off members via get/set accessors is good practice: Objective-C makes it nearly mandatory. In this case it doesn't seem to be necessary, but if one day someone wants to do a check on a change of ID (avoid repitition of the same ID, e.g.) or has the suspicion that a piece of code does something illegal to the ID, then this would be a good place to check or set a trap. If these functions weren't there, all references to ID would have to be replaced by ID(), leading to confusion, errors, etc. Perhaps I missed something. I'm completely oblivious to VB syntax, but the principle is sound.
|
|
-
-
upsidedowncreature


- Joined on 11-20-2007
- Posts 163
|
I think the point is that this is from a derived class so there would be no need to/point in overriding the base class's ID property anyway. Could be wrong but that's how I read it.
What if the hokey cokey really IS what it's all about?
|
|
-
-
RayS


- Joined on 01-22-2005
- Posts 680
|
Well sure you can look at it as being pointless, but think security. If you didn't override it, someone else might. You wouldn't want somebody else overriding code in your base class, would you? This is just classic defensive programming.
EULA: By reading this post and associated disclaimer, you are consenting to agree with the opinions disclosed within. If you disagree with this license agreement, you may not return it for a refund.
|
|
-
-
Spectre


- Joined on 05-09-2007
- Posts 497
|
I admit I missed the WTF the first time, but now I see it. This property overrides the one in the base class, yet does nothing new. It's a mildly amusing equivalent of:
struct A { virtual void M() { /* Do stuff */ }};
struct B : A { void M() { A::M() }};
Okay, guess it's not funny after I explained it. Big-time.
╩юфют√ь ёЄЁрэшЎрь яюЁр эр яхэёш■.
Visit #TDWTF @ SlashNET - the semi-official WTF IRC channel.
|
|
-
-
-
bstorer


- Joined on 02-01-2007
- Alexandria, VA
- Posts 2,332
|
upsidedowncreature:I think the point is that this is from a derived class so there would be no need to/point in overriding the base class's ID property anyway. Could be wrong but that's how I read it. I read it the same way. He's overriding the property but providing no additional functionality.
|
|
-
-
-
Spectre


- Joined on 05-09-2007
- Posts 497
|
ekolis:Yeah, I saw it that way too - but don't you have to explicitly declare things as "virtual" to allow them to be overridden in VB and C# (unlike in Java, where you have to make them "final" to prevent them from be overridden)? I'm not sure whether "overrides" has an implicit "virtual" or not, but if it doesn't, then he's effectively sealed the method, preventing anyone deriving from the derived class from overriding it...
In VB, a method is not overridable by default. But when someone marks it with Overridable, it stays overridable until some derived class marks it with NotOverridable. In other words, a method marked with Overrides only is still overridable.
╩юфют√ь ёЄЁрэшЎрь яюЁр эр яхэёш■.
Visit #TDWTF @ SlashNET - the semi-official WTF IRC channel.
|
|
-
-
Soviut


- Joined on 09-13-2007
- Posts 154
|
bstorer: upsidedowncreature:I think the point is that this is from a derived class so there would be no need to/point in overriding the base class's ID property anyway. Could be wrong but that's how I read it. I read it the same way. He's overriding the property but providing no additional functionality. It could be generated code that just overrode everything in the base class by default. Or he just forgot to do anything with it, heh.
|
|
-
-
pitchingchris


- Joined on 04-30-2007
- Elizabethtown, KY
- Posts 361
|
Soviut:It could be generated code that just overrode everything in the base class by default. Or he just forgot to do anything with it, heh.
I highly doubt it.
|
|
-
-
RayS


- Joined on 01-22-2005
- Posts 680
|
Soviut:It could be generated code that just overrode everything in the base class by default. Or he just forgot to do anything with it, heh.
The WTF would still be the same in that case, just with a different author. Well no, some blame would still be on him for not thinking "what a load of junk, I should delete that".
EULA: By reading this post and associated disclaimer, you are consenting to agree with the opinions disclosed within. If you disagree with this license agreement, you may not return it for a refund.
|
|
Page 1 of 1 (12 items)
|
|
|