iOS design mode-Combined design mode

Source: Internet
Author: User

This blog post will enable you to learn about "what is a tree structure", "what is a combination mode", "the problem that can be solved by combinatorial mode" in software development.

Content outline:

1. Tree-shaped structure

2. Combination mode

3. Write the folder system

1, tree-shaped structure ( great God or Computer foundation very good can be skipped, but this later by using object-oriented code to implement the tree structure, worth reading )

Before introducing the combination design pattern, it is necessary to talk about the tree structure, Baidu "tree structure", you can easily find the relevant basic concepts about the tree structure:

   A tree structure is a hierarchy of nested structures. The outer and inner layers of a tree structure have similar structure, so this kind of structure can be recursively represented.

The various tree graphs in the classical data structure are a typical tree structure: a tree can be simply represented as the root, the left subtree, and the right sub-tree. Saozi right subtree has its own sub-tree.

  

The tree structure is easy to understand, and the same as the upside tree, and then there is a root node, through the root node we can get the root node associated with the child node, through the child node we can get the child nodes:

  

Back to the above from Baidu copy of the basic concept of "tree structure", it refers to the tree structure is a hierarchy of nested structure, look at the following figure, because the tree structure is hierarchical nesting structure, so from the overall and partial point of view,

The outer and inner layers have similar structures, which can be represented by recursive algorithms in the algorithm data structure, but it is important to note that recursion is a process-oriented language, because recursive thought nature is also considered in the execution of code logic.

In addition a mathematical graphic theory is supplemented also by the thing: fractals. This is also the content of fractal graphics theory.

  

And here we need to stand in object-oriented terms, this pattern is a combination of patterns, but from the thought and process-oriented recursive algorithm thinking is similar.

Next we implement the structure of the simple binary tree by code, of course, the realization of the object with Objective-c:

    

1-1. First we need to create a node to represent each element in:

1-2. Then we use the Node node class in VIEWCONTROLLER.M to implement the above two-fork tree

1-3, the final printing to see if the result is not according to the binary tree, from left to right to traverse:

  

2. Combination mode

First look at the UML diagram of the combination mode, do not understand can skip, I also explain not clear, perhaps later will understand.

  

The next step through the code implementation of the combined pattern, similar to the above binary tree, the difference is not a binary tree, the code is the difference between the node class using an array to store the child nodes:

  

2-1. Create a Node object:

 

 

2-2. See how this node is used in VIEWCONTROLLER.M:

  

2-3. Print out the result:

3. Write the folder system

About the folder system, in fact, in the application or PC-side applications are very common, a folder contains multiple subfolders and sub-files, and the subfolder contains its subfolders and sub-files, in turn recursively recursively.

First look at the dynamic:

This is obviously a combination of pattern implementation of the problem domain, so the following directly read the source bar:

< first release, I wash clothes and then come back?? >

Reprint need to indicate the source: http://www.cnblogs.com/goodboy-heyang/p/5226090.html, please respect the fruits of labor.

iOS design mode-Combined design mode

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.