mercredi 26 juillet 2017

Create an interface for heterogeneous sources

I'm studying patterns writing my own examples. But sometimes I got stuck...

I have four stores:

Store1: meat, ice cream and toilet paper.

Store2: ice cream.

Store3: meat.

Store4: ice cream, pasta, vegetables.

Sometimes I want meat from all stores.

Sometimes only ice cream from all stores.

Sometimes only ice cream from a single store.

How should I design an interface for those classes considering not every method would be implemented in every class? I mean, there's no get_ice_cream for the Store2 since there's no meat in the Store2.

Interface segregation could lead to an "interface explosion".

In other hand... people says that multiple inheritance is a bad decision in almost of cases.

I'm stuck trying to deal with that problem.

It would be very nice to have an way to add new Stores and make my IceCream concrete class be able to get all the ice cream from a list of Store objects simply executing the same get_ice_cream method.

Thanks for any help?

Aucun commentaire:

Enregistrer un commentaire