HF-DP1: Strategy Pattern

Source: Internet
Author: User

This is the 1st pattern I study. In here, I will mark down my doubts, Java study, design principles, design pattern.

There are3 design principlesIn this pattern:

1. Identify the aspects of your application that vary and separate them from what stays the same (codeproject)

2. Program to an interface, not an implementation (stackoverflow)

3. Favor composition over inheritance (stackoverflow)

 

Java study:

1. in C ++, absolute C ++ said we need to encapsulate so that we separate codes into interface (. HPP) and implementation (. CPP ). but in Java, just use:

Public interface name {}

Public class name {}

2. in strategy DP, encapsulate algorithms for one interface. and the duck base class needs to be inherited, and use abstract method. by defining an abstract method, the class needs to be defined:

Public abstract class duck {}

3.

UML Notations: (Ref: codeproj link shown before)

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.