Back to list
Views:   6.1K
Replies:  1
Archived

Problem with derived class properties when using a factory

I have created a factory to handle XML Responses, properties are defined in the sub classes or the individual XML Nodes, as depending on the original request, the nodes returned in the XML Response will be entirely different.

The issue I am having is that I am unable to access the sub class properties as they are not defined in the base class, would rather not define them in the base class as they are specific to the derived class and wondered if there was a way arround it, is there another design pattern I could use that could resolve the issue I am having.

Thanks.
Stuart Brant, Apr 05, 2011
Reply 1
Hi Stuart,
First of all, I don't thing that a Factory Method, will help you in the case that all sub-clases are different, factory is only good if all returned instances share the same interface.

What may help you here is to implement the same interface in all subclases. 

For example create a dictionary of properties in the base class and all derived classes implements a "public object GetProperty(string name);" method and also a ReadXml() abstract method, so each XmlMapper knows where to read the properties.
So your "Factory" should instantiate a sub-class that reads the Xml and set its own property's dictionary.



I hope this helps you a little bit.
Diego Barnech, May 11, 2011


Stay Inspired!
Join other developers and designers who have already signed up for our mailing list.
Terms     Privacy     Licensing       EULA       Sitemap      
© Data & Object Factory, LLC.
Made with    in Austin, Texas.      Vsn 1.3.0