Polymorphism with EditableChildList

Polymorphism with EditableChildList

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


Robert posted on Friday, March 16, 2007

To support having different objects in a collection you can create a common interface that inherit form IEditableBusinessObject.
Thats fine and all, but it seems that you have to define the internal methods DeleteSelf(), Insert(object parent) and Update(object Parent) in the common interface, and you dont really want this methods to be exposed like this? I guess you can use reflection in the Update(object parent) method in the collection, but that doesn't seem right eighter.  Is there a clever way to support the update method in the collection without scoping the the internal methods in the objects as public?

Thanks and Brgds
Robert

ajj3085 replied on Friday, March 16, 2007

Yes, define another interface, IMyChildObjectsInternal, which has the methods.  That interface should inherit your public interface.

The key is to scope the interface itself at internal, then have your child objects implement the interface explicitly.  You can't use implicit implementation, because that would force you to make the interface public, which defeats your purpose.

HTH
Andy

Robert replied on Friday, March 16, 2007

Perfect! Thanks Andy.

Copyright (c) Marimer LLC