mercredi 28 août 2019

Can i use class instead of interface in composite design pattern?

I'm writing a program that's going to visualize compound products with input materials which can also be compound products.

Interface: [Product]

Compound item: [CompoundProduct : Product]

Leaf: [Material : Product]

I'm going to visualize the products and materials in TreeView using TreeViewItems, thus i want both the Material and CompoundProduct to include a TreeViewItem object. For this, i want my Product interface to contain a variable, which it can't since it's only an interface.

Is there any reason why i can only find composite design pattern examples with interface implementations? Does it look ugly to use the pattern with class instead of interface?

Aucun commentaire:

Enregistrer un commentaire