Reusable policy Composite Synthesis/aggregate Aggregation

Source: Internet
Author: User

Priority: composit | aggregate. Do not use special types of extends and association.
Aggregation: it indicates the 'havn' relationship or the relationship between the whole and the part.

Composition can be understood as a strongly correlated relationship, with a much stronger 'havn' relationship. A new merged object has full control over its components, including their creation/destruction,

Component Objects in a compositing relationship cannot be shared with another compositing relationship.

A component object belongs to only one compositing relationship at a time.

Synthesis is the aggregation by value, and aggregation is the reference aggregation by reference)

· Composite/aggregation Reuse

The only way to store/retrieve component objects for new objects is through interfaces.

The internal details of the component object. The new object is invisible.

This reuse mechanism supports packaging/requires less Dependencies

Each new object can focus on a task.

New objects can dynamically reference instances of the same type as component objects. For example, setuserlist (User userobj) can be seen as an interface in some users.

This merging/aggregation multiplexing mechanism has multiple instances to be managed

· Use extends

Extends is a unique reuse mechanism of OO and can be abused easily.

Inheritance is the reuse of types. It extends or adds new functions to existing functions by extending the implementation of an existing object. The basic class must capture common attributes/form, the subclass must extend/override some attributes/form.

Inheritance destroys the encapsulation of the superclass because it exposes the processing details to the subclass.

Water Wave effect. If the superclass processing mechanism is changed, the corresponding changes to the subclass are very large.

Is a difference from has

Is a represents a class.

Has a indicates that a class is a role of a class.

· The composite/aggregation reuse mechanism can be applied to almost any environment, but inheritance can only be applied to a limited environment.

 

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.