Interface Question

D

dan

Hi,

In my application I have used the Factory Design method to model a portion
of my business layer. Each object I create using the factory method share
the same actions (subs/function) which I use an interface to interact with
and it works great. However, I have run into a problem because each object
might share the same actions however the attributes (properites) are
different (hidden) and I need acess to them. At the time of the design these
properties were going to remain hidden but now with a change in business
logic I need access to them. Without completely breaking my design is there
a solution out there to apply?

Thanks
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

dan said:
Hi,

In my application I have used the Factory Design method to model a portion
of my business layer. Each object I create using the factory method share
the same actions (subs/function) which I use an interface to interact with
and it works great. However, I have run into a problem because each
object
might share the same actions however the attributes (properites) are
different (hidden)

private you mean?
and I need acess to them. At the time of the design these
properties were going to remain hidden but now with a change in business
logic I need access to them. Without completely breaking my design is
there
a solution out there to apply?


The idea of having a common interface is that you can treat any instance in
the same way, no matter what type that instance is.
What you want will break the above. You will NEED TO KNOW the exact type of
the instance created in order to access its particular properties.


Are you sure this is the only way to go?

At the very last resort you could a lookup method:

public object GetPropertyValue( string propertyname)
{
switch propertyname
{
case "prop1" return 1;
case "prop2" return "whatever";
}
}
 
D

dan

Thanks for the post. I do need to get some properties from each object and
these properties are not common between the objects. Do you have any other
ideas?

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top