I was reading a book on spring and encountered this example.
Have a abstract product class containing two attributes - name and price. Have a battery class which extends product class and adds one more attribute (isRechargable).Have a CDDrive class extending product and adding (capacity) as extra parameter.
In the real world we will have many-2 products each having different-2 attributes.So how will i model it? Will i have a class for each product (which does not make sense to me).
So, can you guys please suggest a pattern for achieving this?
At first I thought decorator pattern (Have never used though) but then it will only be useful if I am dealing only with common properties. Suppose if customer orders 2 cds, 1 batteries. Then I can use something like new CDDrive(new CDdrive(new Battery())).cost(), but that is not the case here.
Thanks, Ouney
Aucun commentaire:
Enregistrer un commentaire