Design Pattern learning-simple factory pattern (opening)

Source: Internet
Author: User
After so long winter vacation, the learning efficiency is not very high, and many of the planning objectives are not completed, but there are still some gains, that is, the book "big talk Design Pattern, it gave me a deeper understanding of OOD and many vague concepts in the past. I was confused about the concept of design patterns. Now I know that ProgramIt is easy to maintain, flexible, easy to expand, and reusable. We need to consider reducing the Coupling Degree of the program through encapsulation, inheritance, and Polymorphism to achieve "High Cohesion, low coupling ". The design pattern makes the program more flexible, modified, and easy to reuse. I just want to say that this book is really a rare good book !! In the next period, I will record the classic design patterns in this book.

Simple factory Mode

First, you must understand the business encapsulation. Business encapsulation is to separate the business logic from the page logic to reduce their coupling. For example, to implement a four-character program, I like to write the program in a main program. CodeLater, I learned functions, classes, and methods, but the teacher only asked me to do this. I don't know why I want to do this and I think it will be slow. It is undeniable that writing in this way sacrifices performance, but in exchange for later modification, the convenience of maintaining the program, and the program structure is very clear.
For example, for the four middleware programs, we write an operation class to determine what operations to perform, that is, business encapsulation.
What is the simple factory model? For example, the four operators have four types of operations. The classes for adding, subtraction, multiplication, and Division operations are all inherited from the Operation classes, and the classes for the four operations are reloaded. In this way, there is no connection between each operation. When modifying an operation method, other calculation methods are not affected and the coupling degree is reduced. Finally, a factory class is used to determine which operation to execute. For example, addition is the addition class that executes the inherited operation class.
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.