iOS design mode-appearance mode (also known as store mode) and decorative mode

Source: Internet
Author: User

What is the appearance mode?

The appearance mode provides a unified interface for a different set of interfaces in a subsystem. The appearance defines the upper interface, which makes the subsystem easier to use by reducing the complexity and hiding the communication and dependencies between the subsystems.

For example, a subsystem has a different set of classes, some of which depend on each other. This makes it difficult for the client to use the classes in the subsystem because the client needs to know each class. The façade is the entrance to the entire subsystem. Some clients only need some basic subsystem behavior, and the subsystem's classes do not do too much customization, the appearance of such a client provides a simplified interface. Only clients that need to customize more behavior from the classes of certain subsystems will focus on the details behind the façade.

Appearance mode: Provides a unified interface for a set of interfaces in the system. The appearance defines a high-level interface that makes the subsystem easier to use.

When do I use appearance mode?

@: Subsystems are becoming progressively more complex. There are many classes that evolve in the process of applying patterns, and you can use appearances to provide a simpler interface for these subsystems.

@: You can use the appearance to layer the child system. Each subsystem level has an appearance as an entry point. Allowing them to communicate through their appearance simplifies their dependencies.



What is decorative mode?

Decoration mode, without modifying the original code to dynamically add new behavior and responsibilities to the object, in terms of expansion, decorative mode than the generation of sub-class more flexible.

In Objective-c, the system provides two implementations, category (class) and delegate (delegate).

Category is a powerful mechanism that allows you to dynamically add methods to existing classes without having to subclass them. The new method is added to the compiler, and these methods are executed at the same time as the other methods of the extended class. It may be slightly different from the adorner pattern because the category does not save references to the extended class. Note: You can also add methods to classes in Cooca, in addition to extending your own classes.

delegate, as another decorative mode, is a mechanism for interacting with other objects. For example, when you use UITableView, you have to implement Table:numberofrowsinsection: method.

When to use decorative mode?

@: You want to add responsibilities to a single object in a dynamic, transparent way without affecting other objects.

@: You want to extend the behavior of a class, but you can't. Class definitions may be hidden, not subclasses, or each of the classes ' behaviors can be extended to support each feature combination, resulting in a large number of subclasses.

@: An extension of the responsibilities of a class is optional.

What is the difference between the appearance mode and the policy mode?

Changes from outside, each node does not know the change, this is the appearance mode. From internal changes, each node knows a predefined set of change patterns, which is the policy pattern.


Reference article:

http://blog.jobbole.com/48166/

Demo Address:

https://[email protected]/guoshimeihua/memoryandcommanddemo.git

iOS design mode-appearance mode (also known as store mode) and decorative mode

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.