That would be doable in the real world but in a program, it’s not as simple as running a loop. You could try the direct approach: unwrap all the boxes, go over all the products and then calculate the total. The whole structure looks like an upside down tree. How would you determine the total price of such an order?Īn order might comprise various products, packaged in boxes, which are packaged in bigger boxes and so on. Orders could contain simple products without any wrapping, as well as boxes stuffed with products.and other boxes. Say you decide to create an ordering system that uses these classes. These little Boxes can also hold some Products or even smaller Boxes, and so on. A Box can contain several Products as well as a number of smaller Boxes. Using the Composite pattern makes sense only when the core model of your app can be represented as a tree.įor example, imagine that you have two types of objects: Products and Boxes.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |