当前位置:网站首页>23 design models
23 design models
2022-07-03 06:11:00 【Master core technology】
One 、 Design model overview
Definition
Design patterns (Design Pattern) It's a summary of code development experience of predecessors , It's a series of solutions to specific problems . It's not a grammatical rule , It's a set to improve code reusability 、 Maintainability 、 Readability 、 Solutions for robustness and security .
The essence of design pattern is the practical application of object-oriented design principle , It's encapsulation of classes 、 Inheritance and polymorphism as well as the full understanding of class association and composition .
23 Design models :GoF23
1) Create pattern :
The singleton pattern 、 Factory mode 、 Abstract factory pattern 、 Builder pattern 、 Archetypal model .
2) Structural mode :
Adapter pattern , Bridging mode , Decoration mode , Portfolio model , Appearance mode , The flyweight pattern , The proxy pattern
3) Behavioral patterns :
Template method pattern , Command mode , Iterator pattern , Observer mode , Intermediary model , Memo mode , Interpreter mode , The state pattern , The strategy pattern , Responsibility chain pattern , Visitor mode .
OOP The seven principles
* Opening and closing principle : Open to expansion , Turn off for changes
Richter's principle of substitution : Inheritance must ensure that the properties owned by the superclass are still valid in the subclass
The principle of Dependence Inversion : Interface oriented programming , Don't program for implementation .
Principle of single responsibility : Control the granularity of the class 、 Decouple objects 、 Improve its cohesion .
Interface isolation principle : To create the specialized interfaces they need for each class
Dimitar's law : Just talk to your direct friends , Not with “ A stranger ” speak .
Synthetic multiplexing principle : Try to use association relations such as composition or aggregation to achieve , Second, consider using inheritance relationship to achieve .
Two 、UML
UML Concept
Unified modeling language (Unified Modeling Language,UML) It's a visual modeling language for software design . It is characterized by simplicity 、 Unified 、 Graphical 、 It can express dynamic and static information in software design .UML From different perspectives of the target system , Define the use case diagram 、 Class diagram 、 Object graph 、 State diagram 、 Activity diagrams 、 Sequence diagram 、 Collaboration map 、 Component diagram . Deployment diagram, etc 9 Seed map .
Class diagram Overview
Class diagram (Class diagram) It shows the static structure of the model , Especially the classes that exist in the model 、 The internal structure of classes and their relationships with other classes . Class diagrams don't show transient information . Class diagram is the main part of object-oriented modeling .
The function of class diagram
In software engineering , A class diagram is a static structure diagram , Describes the collection of classes of the system , The properties of a class and the relationships between classes , It can simplify people's understanding of the system ; Class diagram is an important product of system analysis and design , It's an important model for system coding and testing .
Class diagram representation 
+ Express public
- Express private
# Express protected
The complete representation of attributes is : visibility name ︰ type [ = The default value ]
The complete representation of a method is : visibility name ( parameter list ) [ : Return type ]
The representation of the relationship between classes
1) Connections
Association is a kind of reference relationship between objects , Used to represent the relationship between one class of objects and another class of objects . Association is the most commonly used relationship between classes , It can be divided into general relationship 、 Aggregation and composition . Association can be divided into one-way Association , Two way connection , Self correlation .
1, One way Association 
stay UML One way Association in the class diagram is represented by a solid line with an arrow . The picture above shows that every customer has an address , It's by making customer Class holds a type of Address Member variable class implementation of .
2, Two way connection 
It's easy to see from the picture above , The so-called two-way association is that both sides hold each other's type of member variables . stay UML In class diagram , Bidirectional association is represented by a straight line without an arrow . The picture above shows Customer Maintain one in the class List, It means that a customer can buy more than one product ; stay Product Maintain one in the class customer The member variable of type indicates which customer purchased the product .
3, Self correlation 
Self correlation in UML The class diagram is represented by a line with an arrow pointing to itself . The picture above means Node Class contains the type Node Member variables of , That is to say "“ Self contained ”.
2) Aggregate relationship
Aggregation is a kind of association , It's a strong correlation , It's the relationship between the whole and the part . Aggregation relationships are also implemented through member objects , The member object is a part of the whole object , But member objects can exist independently of the whole object . for example , The relationship between school and teachers , The school contains teachers , But if the school is closed , Teachers still exist . stay UML In class diagram , The aggregation relationship can be represented by a solid line with a hollow diamond , Rhombus pointing to the whole .
3) synthetic relation
Composition represents the relationship between the whole and the parts of a class , But it's a stronger aggregation . In a combinatorial relationship , The whole object can control the life cycle of some objects . Once the whole object doesn't exist , Some objects will not exist , Some objects cannot exist apart from the whole . for example , The relationship between head and mouth , No head , The mouth doesn't exist . stay UML In class diagram , A combination is represented by a solid line with a solid diamond , Rhombus pointing to the whole .
4) Dependency relationship
Dependency is a kind of usage relationship , It's the weakest way of associating objects , It's a temporary connection . In the code , Methods of a class pass through local variables 、 Method or a call to a static method to access another class ( Dependent class ) Some of the ways to accomplish some of the responsibilities . stay UML In class diagram , Dependencies are represented by dotted lines with arrows , The arrow points from the use class to the dependent class . The diagram below shows the relationship between driver and car , The driver drives the car :
5) Inheritance relationships
Inheritance is the most coupling relationship between objects , To express a general or special relationship , Is the relationship between the parent class and the child class , It's an inheritance relationship . stay UML In class diagram , The generalization relationship is represented by a solid line with a hollow triangle arrow , The arrow points from the child class to the parent class . When the code is implemented , Use object-oriented inheritance mechanism to achieve generalization relationship . for example ,Student Classes and Teacher Classes are Person Subclasses of classes , The class diagram is shown in the following figure ;
6) Realization relationship
Implementation relationship is the relationship between interface and implementation class . In this relationship , Class implements the interface , The operations in the class implement all the abstract operations declared in the interface . stay UML In class diagram , The implementation relationship is represented by a dotted line with a white triangle arrow , The arrow points from the implementation class to the interface . for example , Cars and boats make transportation possible , The class diagram is as shown in figure 9 Shown .
边栏推荐
- Kubernetes notes (VIII) kubernetes security
- ODL framework project construction trial -demo
- Openresty best practices
- Oauth2.0 - using JWT to replace token and JWT content enhancement
- 轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷
- 1. Somme des deux nombres
- [Zhao Yuqiang] deploy kubernetes cluster with binary package
- If function of MySQL
- Why should there be a firewall? This time xiaowai has something to say!!!
- Fluentd is easy to use. Combined with the rainbow plug-in market, log collection is faster
猜你喜欢

项目总结--2(Jsoup的基本使用)

Project summary --04

Es remote cluster configuration and cross cluster search

Oauth2.0 - using JWT to replace token and JWT content enhancement

pytorch 搭建神经网络最简版

理解 YOLOV1 第一篇 预测阶段

CKA certification notes - CKA certification experience post

Phpstudy setting items can be accessed by other computers on the LAN

Analysis of Clickhouse mergetree principle
![[Zhao Yuqiang] deploy kubernetes cluster with binary package](/img/cc/5509b62756dddc6e5d4facbc6a7c5f.jpg)
[Zhao Yuqiang] deploy kubernetes cluster with binary package
随机推荐
Project summary --04
Cesium 点击获三维坐标(经纬度高程)
Leetcode solution - 02 Add Two Numbers
Kubernetes notes (VIII) kubernetes security
Fluentd facile à utiliser avec le marché des plug - ins rainbond pour une collecte de journaux plus rapide
技术管理进阶——你了解成长的全貌吗?
1. Sum of two numbers
从小数据量分库分表 MySQL 合并迁移数据到 TiDB
[teacher Zhao Yuqiang] redis's slow query log
Migrate data from Amazon aurora to tidb
Mysql database binlog log enable record
Oauth2.0 - user defined mode authorization - SMS verification code login
智牛股项目--04
Kubernetes notes (VII) kuberetes scheduling
Click cesium to obtain three-dimensional coordinates (longitude, latitude and elevation)
[Zhao Yuqiang] deploy kubernetes cluster with binary package
Oauth2.0 - using JWT to replace token and JWT content enhancement
Fluentd is easy to use. Combined with the rainbow plug-in market, log collection is faster
[teacher Zhao Yuqiang] Cassandra foundation of NoSQL database
[teacher Zhao Yuqiang] the most detailed introduction to PostgreSQL architecture in history