Basic concept of design pattern

Source: Internet
Author: User

Dependency is a good distinction, it is the weakest coupling, in Java as local variables, method parameters, or calls to static methods, such as the following example: Driver class depends on the car class, driver three methods to demonstrate the dependency of the three different forms.


Association relationships are typically implemented in Java using member variables, sometimes in the form of method parameters. Still using driver and car examples, using the method parameter form can represent a dependency or an association relationship, after all, we cannot express semantics too accurately in the program. In this example, the member variable is used to express the meaning: The car is my own car, I "own" the car. Using the method parameter expression: The car is not mine, I am just a driver, others give me what car I will drive what car, I use this car.


The aggregation relationship is a relatively strong association, which is generally implemented in Java using the member variable form. There is a whole and a part relationship between objects. For example, in the previous example


To represent a combined relationship, the constructor is often used to achieve the purpose of initialization, such as in the example above, plus a construction method with the car parameter


public Driver(Car car){       mycar = car;  }


Basic concept of design pattern

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.