i am a newbie to the design patterns and here is my question
if we have an abstract class with few classes that implement it and each of this classes has different attributes.
now i have another (Manager class) that holds an array of the abstract class and i want to put a search method in it ... how can i do that without casting to the concrete classes ?
i have got 2 ideas:
First One : adding an extra levels of interfaces (ie. rather than casting to concrete class i will be casting to an interface ) which goes with the code to interface not implementation rule... but this way when i add another class i will have to make an interface for it and i will also have to edit the manager (client) , which doesnt seem very good.
Second Solution: it look somewhat strange and still needs enhancements but its main goal is to make the manager or any other client works with abstract class without knowing any thing about who extends it or its attributes.
the solutin is as folows : each new item added will have to overide one interface that enforces it to generate a complete discription of its fields for example a car object will have to return a hash map having the folowing
field : { fieldType , fieldValue }
example
- model : { text , "ford" }
- manifactureDate : { Date , "12/1/89" }
and each object will have also to implement a method called compareFields that take a hash map like this and compare it to its field and return true or false.
now by this way i have solved many issues -for the gui i will only have to make a rendering engine for this hashmap that can display any item without having to know what its type. (again the gui is another client for the abstract class)
-for the search i can get a hash map that contain the fields the user enters in the search form and loop on the abstract items and invoke the compare fieldmethod
i still don't how i will handle the complex object (that have another object as its attributes)
i dont know what kind of pattern is this .. it is just an idea that i thought about.
EDIT : CONCRETE EXAMPLE
if i have an abstract item Class with a car and bus and boat that implements it,,and each of this classes has different attributes.... how can a manager for example traffic manager search for a certain item using the abstract class without casting to car or bus... really sorry for the long question