Can you please explain. I dont know about design patterns. Also please share
some good book for design patterns.
thanks

On Fri, Sep 23, 2011 at 4:07 PM, Prem Krishna Chettri <[email protected]>wrote:

> This is Simple query related to Factory Design Pattern... Have a look at
> the Auto Registration of Factory Design pattern..
>
>
> :)
> Prem
>
>
> On Fri, Sep 23, 2011 at 3:02 PM, algo geek <[email protected]> wrote:
>
>> You have a library provided by the vendor. All you have is header files
>> and library files.
>> Library contains the class Shape and there is whole hierarchy tree (i mean
>> classes which derive from this base class).
>> Now you want to add some function "getArea" (not originally present in the
>> class or any of its derived class) in the class "Shape" , you dont have the
>> source code.
>>
>> Using this library, you have written a lot of code. Now you have to make
>> some changes so that, any object of Shape class (or its derived class) will
>> be able to call this function.
>> With your strategy, you should be able to override the definition of this
>> function in the derived class.
>>
>> I think it is related to design patterns, not sure.
>> I gave the solution that : we will use MyShape , and use composition. i.e.
>> will create the object of Shape class inside this "NewShape" class and
>> interface can be made. Internally, we can call the functions of "Shape"
>> object. That will work fine. But we have to do this for the whole design
>> hierarchy. Secondly, if there is some changes by the vendor in future in the
>> library, i have to change my new design tree.
>> e.g.
>> class Shape {
>>    public : void draw();
>>               void clear();
>> }
>> class Circle : public Shape{
>>    public : void draw();
>>               void clear();
>> }
>> class Rectangle: public Shape{
>>    public : void draw();
>>               void clear();
>> }
>>
>>
>> class NewShape{
>> private Shape * obj;
>>    public : void draw(){ obj->draw(); }
>>               void clear() { obj->clear(); }
>>               int getArear(){
>>                      //implementtation of getArea function
>>               }
>> }
>>
>> class NewCircle : NewShape{
>>    public : void draw(){ (Circle*)obj->draw(); }
>>               void clear() { (Circle*)obj->clear(); }
>>               int getArear(){
>>                      //implementtation of getArea function specific to
>> circle
>>               }
>> }
>> class NewRectangle : NewShape{
>>    public : void draw(){ (Rectangle*)obj->draw(); }
>>               void clear() { (Rctangle*)obj->clear(); }
>>               int getArear(){
>>                      //implementtation of getArea function
>>               }
>> }
>>
>> I know this solution is not good.. please provide a better approach for
>> this.
>> Please let me knw if anything is not clear.
>>
>>
>>
>>
>> Thanks in advance.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to