Book author strategy regarding hiding inherited member.

Book author strategy regarding hiding inherited member.

Old forum URL: forums.lhotka.net/forums/t/1493.aspx


rxelizondo posted on Sunday, October 15, 2006

I noticed that when Rocky created the ProjectResources class by inheriting from BusinessListBase, he decided to create a method called “GetItem(int resourceId)” that he uses to retreived a ProjectResource object.

 

Rather than having this method he could also have implemented an indexer and simply use the “new” keyword so that the compiler wouldn’t complain about hiding inherited members.

 

Never the less he didn’t, so my question is, anyone knows why did he decide to go that way? Why not an indexer? Is hiding inherited members one of those obscure object oriented nono practice?

 

Thanks.

Brian Criswell replied on Sunday, October 15, 2006

Yes, hiding is generally a nono, because you can cast to the base class and get around the inherited behaviour.  Also, if you have an integer indexer, you would be hiding the default implementation of this[int] (which, in my opinion would really be a nono).  This also does not work very well if you have more than one id property for a given item.  GetItem(id) is therefore a safer and more consistent means of getting an item from a list by its identifying properties.

Copyright (c) Marimer LLC