Modular design of iOS programs

Source: Internet
Author: User

I. Overview of MODULAR Design:

Modular (block-based design): a range of different functions or the same function of different performance, different specifications of the product on the basis of functional analysis, the division and design a series of functional modules, through the selection and combination of modules to form a variety of customized products to meet the different needs of the market.

Modular design is one of the green design methods, the green design refers to "the product throughout the life cycle, focusing on product environmental attributes (Disassembly, recyclability, maintainability, reusable, etc.) and as a design goal, in meeting the requirements of environmental objectives, while ensuring that products should have the function, service life, Quality and other requirements. "

The principle of green design is recognized as the "3R" principle, that is, reduce,reuse, Recycle, reduce environmental pollution, reduce energy consumption, recycling of products and components recycled or reused.

Second, the characteristics of modular design:

    • Control the complexity of the programming: the modular design will be the overall cutting package, each small function can be encapsulated into a small module, independent operation, non-impact, control the overall complexity.
    • Each module is relatively independent, the function is single, the structure is clear, the interface is simple: the module after the code is relatively independent, the function is single, only in the outside to provide the necessary interface for outside calls, the internal realization process, hidden inside, object-oriented interface programming, make the structure clear, interface simple, can achieve high cohesion, low coupling effect.
    • Versatility: The modular design needs to ensure that the extracted functionality is packaged in a flexible way, both in terms of the functionality supported by the SDK and the size of the screen, so that the application can be deployed on the basis of the minimum supported system versions and adapted to different screens.
    • Avoid the repetitive work of program development: Each project will be more or less involved in the same function and UI display, the same functionality or interface UI modularity, it is undoubtedly able to avoid the duplication of program development work, but also to improve the quality of the code.
    • Shorten the development cycle: When the features and UI interfaces involved in the project are modularized in advance, they need to be called directly and assembled, which can shorten the development cycle and avoid wasting resources.
    • Easy maintenance and functional expansion: Because the overall functionality is modular, each function is only a small function point, which is relatively easy to maintain. There are new requirements, need to add new function points, but also convenient for unified expansion, before the modular good code also need not change, easy to maintain.

Third, the division of the module:

The partitioning of modules can be divided at the architectural, business, or functional levels:

(a) architectural level:

Each project will have an overall architecture, which, like a foundation, can only be developed on the basis of a built-in architecture for the corresponding module functions. The structure of the project in the construction process, from the level, can be set up in the following ways (the following is the architecture of the service):

Project directory "Urmingservice", the main development work area, the whole is divided into "Classes", "Resources"/"Tools" and "supporting Files" three large directories:

1, in the "Classes" in this directory each module and according to the MVC design pattern to build, classify, convenient management, also increased the readability of the code level, we in the "Famous service" project is divided into "home", "message", "release", "Order" and "my" five large modules, When building the architecture, on the basis of these major business modules, add a "public" module, which is mainly placed in some items of the top level of the base class or common class, such as navigation bar and the bottom of the overall style of the tab bar settings, can also be used in the MVC mode of hierarchical management.

2, "Resources"/"Tools" in this directory, is mainly categorized by the function of the packaging of the tool class and the entire project will be used in the picture resources, for the picture resource placement of the hierarchical directory can be broadly divided into: Guide page, navigation bar, tab bar and display class.

3, "Supporting Files" in this directory, mainly used to place the entire project will be used in the local file, the application icon and the Start Page image management "Images.xcassets", System global configuration files, internationalization files and so on.

(b) Operational aspects:

The division of Business-level modules is related to the Business module division of product design, which can divide different business into sub-modules, which is a relatively whole and independent division, such as "Famous service" We divide the business module into "Home", "message", "release", "Order" and "my", Each relatively independent business module is assembled to complete the theme and business of "famous service".

The unification of business modules and the unity of UI interface style under the business module is conducive to the creation of a series of similar styles of products, which can be based on the architecture and functional modularity, the same products in the overall modular, the implementation of factory-customized development.

Advantage: The division from the business level will make each module more independent.

Cons: Handling public transactions can become cumbersome.

(iii) Functional aspects:

Functional level of the module division, is to function independently, achieve high cohesion, low coupling. Each small function module can run, can debug, can test, each function is basically completely independent, there is no interdependent relationship.

But the function is unable to divide with the business, we in the development, needs the macroscopic control business and the function relations, for similar business module, needs unifies the difference development, the cooperation completes, prevents the duplication work.

Advantages: Independent and clear responsibilities.

Shortcomings: The division of its responsibility, lack of continuity and macro.

Iv. FAQs and Solutions:

1. Problem: Same function, multiple use.

Solution: Separate functions according to their responsibilities and develop their respective function modules.

Can be run independently, can be compiled into a static library, there is a complete internal interface documentation.

Compliant: Removable rows, recyclability, maintainability and repeatability.

2, Problem: If the module is split, each module will often have third-party library dependencies, such as public libraries. How to avoid the issue of duplicate references and reference versions.

Solution: Solve with CocoaPods software.

A third-party dependency is all done by its own podfile configuration, which is packaged in the project based on the third party referenced in the project, and it merges references if multiple duplicate references are encountered. Our modules can also be made into separate podspecs files for other modules to reference, so that the module can be upgraded and updated.

3. Question: What is the specific function of each module after the function modularization?

Breaking down the functionality in the application into separate modules poses a new challenge-we need to make sure that these interdependent parts work together.

Another feature of a modular system is the externally dependent declaration. Many components have a certain need for external conditions. There is a big premise to using dependency patterns to maintain dependencies between components in a module system: We have to follow a series of rules.

The first rule is backwards compatibility: If a new version is released, then all contracts that can be established under the previous version must also be able to work under the new version.

The second rule is that the components in the system need to accurately describe what they need. When the dependency of a module changes, it must be said, so that the system can accurately confirm whether these dependencies are satisfied.

Five, modular design Overview:

The most important property of a module is that they should be as independent and self-contained as possible, and the module should be designed to provide a full set of functions so that the other parts of the program interact with it clearly, and the functionality provided by the module must be complete so that its callers can picking.

Modularity is designed to reduce cycle dependence, reduce coupling, and improve the efficiency of design and development. To do this, we need to have a design rule that all modules are designed under this rule. Good design rules, the coupling of dense design parameters will be categorized as a module, and this division of work tasks. While the modules interact with each other through a fixed interface (so-called visible parameters), the internal implementation (so-called implicit parameters) is freely played by the development team of the module.

Last but not least: the normalization of method naming is important, and annotations are important, and if there is no comment, only the developer's mind is clear, so the necessary annotations will facilitate later code maintenance and improve efficiency. The main thing for each interface is what to do, which can be described appropriately in the header file,

Reference documents:

http://doruby.com/projectmanage/2013/04/12/block-based-design/

Http://developer.51cto.com/art/201001/179842_1.htm

Http://book.51cto.com/art/201007/212898.htm

http://blog.csdn.net/newjerryj/article/details/7749901

http://blog.csdn.net/optman/article/details/2319450

http://blog.csdn.net/jyc1228/article/details/4636037

Modular design of iOS programs

Related Article

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.