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



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



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



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



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



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



  • @upsidedowncreature said:

    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. 



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



  • @ekolis said:

    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 <font face="Courier New">Overridable</font>, it stays overridable until some derived class marks it with <font face="Courier New">NotOverridable</font>. In other words, a method marked with <font face="Courier New">Overrides</font> only is still overridable.



  • @bstorer said:

    @upsidedowncreature said:

    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. 



  • @Soviut said:

    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.



  • @Soviut said:

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

Log in to reply