[Java Notes] 23 design modes (incomplete)

Source: Internet
Author: User

1. Single Case design mode

Singleton design Pattern: guarantees that a class has only one instance and provides a global access point to access it.

1) Privatization of construction methods

2) Declare an object of this class

3) Provide an external static method to obtain an object instance

For example:

Class singleton{

private static Singletho1 s = new Singletho1 ();

Private Singletho1 () {}

public static Singletho1 getinstance () {

return s;

}

}

2. Template approach mode (Templete method)

Template method Pattern: Defines the skeleton of an algorithm in an operation, and delays the implementation of some mutable parts into subclasses. Template method pattern allows subclasses to be unchanged

The structure of an algorithm can redefine some specific steps of the algorithm.

[Java Notes] 23 design modes (incomplete)

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.