The Daily WTF: Curious Perversions in Information Technology
Welcome to TDWTF Forums Sign in | Join | Help
in Search

Override it all

Last post 03-20-2008 5:31 AM by RayS. 11 replies.
Page 1 of 1 (12 items)
Sort Posts: Previous Next
  • 03-19-2008 2:50 AM

    Override it all

    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

  • 03-19-2008 7:44 AM In reply to

    • TGV
    • Top 500 Contributor
    • Joined on 10-09-2005
    • Posts 90

    Re: Override it all

    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. 

  • 03-19-2008 8:28 AM In reply to

    Re: Override it all

    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?
  • 03-19-2008 8:37 AM In reply to

    • RayS
    • Top 25 Contributor
    • Joined on 01-22-2005
    • Posts 680

    Re: Override it all

    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.
  • 03-19-2008 8:40 AM In reply to

    Re: Override it all

    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.
  • 03-19-2008 8:41 AM In reply to

    Re: Override it all

    He got the object oriented features right. Its good practice to shield them from your members, even derived classes. Although, in your case, if the base class already has an ID property, you don't need to make a property to expose the Base's id. (unless the base's property is protected)  Thats the only thing I see wrong. Everything else looks fine, and with that layout, he can easily add some validation or range checking.

  • 03-19-2008 8:43 AM In reply to

    Re: Override it all

    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. 

  • 03-19-2008 2:14 PM In reply to

    Re: Override it all

    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...

  • 03-19-2008 3:10 PM In reply to

    Re: Override it all

    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.
  • 03-19-2008 8:13 PM In reply to

    Re: Override it all

    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. 

  • 03-19-2008 10:26 PM In reply to

    Re: Override it all

    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.

  • 03-20-2008 5:31 AM In reply to

    • RayS
    • Top 25 Contributor
    • Joined on 01-22-2005
    • Posts 680

    Re: Override it all

    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)
Powered by Community Server (Non-Commercial Edition), by Telligent Systems