Interfaces do not provide any method implementation and can not be instantiated. Interfaces are implemented as abstract classes in C++. Virtual void remove(Component *uComponent)=0 Virtual void add(Component *uComponent)=0 Interface implementation using namespace std Listing 1 shows the implementation of the interface named ComponentInterface Listing 1. getChildName(): Prints the name of the node.remove(): Removes a child from the tree.We are going to implement an Interface which will contain the following virtual methods: Implementing the Composite Design Pattern Furthermore, we can call the same methods on the main view, sub-view or buttons.įor example, we can print the name of every child belonging to the Main View or to Sub-view 1 with the same method call. Image 2 Tree-like structure viewīy placing each view in a tree-like structure, we have a unified access point to every view. If we apply a Composite Design Pattern to the application above, we can treat the whole application as a tree-like structure (figure 2). The Composite Design Pattern provides a way to create a tree structure that can handle a nested group of items.įor example, the image below shows an application with a main view, sub views and buttons.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |