In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Preface of design pattern-- UML class figure 1, UML class diagram 1, class
Class (Class), which encapsulates data and behavior, is an important part of object-oriented, and is the general name of a collection of objects with the same attributes, operations and relationships. In the system, each class has a certain responsibility, which refers to what kind of function the class wants to accomplish and what kind of obligations it should undertake. A class can have multiple responsibilities, and a well-designed class generally has only one responsibility. When defining a class, decompose the responsibilities of the class into the properties and actions of the class (that is, methods). The attribute of the class is the data responsibility of the class, and the operation of the class is the behavior responsibility of the class. Design class is not only the most important part of object-oriented design, but also the most complex and time-consuming part.
When the software system is running, the class will be instantiated into an object (Object), which corresponds to a specific thing and is an instance of the class (Instance).
Class diagrams (Class Diagram) use different classes that appear in the system to describe the static structure of the system, to describe different classes and the relationship between them.
In the system analysis and design stage, classes can usually be divided into three types, namely entity class (Entity Class), control class (Control Class) and Boundary Class class.
Entity classes: entity classes correspond to each entity in the system requirements, which usually need to be stored in permanent storage and are generally recorded using database tables or files. Entity classes include both classes that store and transfer data, as well as classes that manipulate data. The entity class comes from the nouns in the requirement description, such as students, commodities and so on.
Control class: the control class is used to reflect the execution logic of the application and provide corresponding business operations. Abstracting the control class can reduce the coupling between the interface and the database. The control class is generally a noun transformed from a verb-object phrase (verb + noun), such as adding a commodity to a commodity, registering a user registration class, and so on.
Boundary class: the boundary class is used to abstract the interactive objects between external users and the system, including interface classes, such as dialog boxes, windows, menus and so on.
In the initial stage of object-oriented analysis and design, entity classes are usually identified and the initial class diagram is drawn, which can also be called domain model, including entity classes and the relationship between them.
2. UML class diagram
In UML, a class is represented by a rectangle with a delimited line that contains the class name, attributes, and actions.
The class diagram is divided into three layers, the first layer is the name of the class, if it is an abstract class or interface, it is represented in italics, in which the upper part of the interface name is modified; the second layer is the member variables of the class, usually fields and attributes; and the third layer is the member methods of the class. The member variables of the class and the modifiers of member methods are +, #, and -, which represent public, protected, and private, respectively.
In the UML class diagram, a class generally consists of three parts:
(1) the first part is the class name: each class must have a name, and the class name is a string.
(2) the second part is the Attributes of the class: attributes refer to the properties of the class, that is, the member variables of the class. A class can have as many attributes as you want, or it can have no attributes
UML specifies that attributes are represented as follows:
Visibility name: type [= default]
Where:
"visibility" indicates whether the attribute is visible to elements outside the class, including public, private, and protected, represented by the symbols +, -, and # in the class diagram, respectively.
The name represents the property name and is represented by a string.
Type represents the data type of the attribute, either a basic data type or a user-defined type.
The default is an optional, that is, the initial value of the property.
(3) the third part is the Operations of the class: the operation is the behavior that can be used by any instance object of the class, and it is the member method of the class.
The operation specified by UML is expressed as follows:
Visibility name (parameter list) [: return type]
Where:
The definition of visibility is the same as the visibility definition of an attribute.
"name" is the name of the method, represented by a string.
The "parameter list" represents the parameters of the method, its syntax is similar to the definition of attributes, the number of parameters is arbitrary, and multiple parameters are separated by commas.
The return type is optional and represents the return type of the method, depending on the specific programming language, can be a basic data type, a user-defined type, an empty type (void), and no return type if it is a constructor.
Second, the relationship between classes
The types of relationships between classes: Realization (implementation), Generalization (generalization), Dependency (dependency), Association (association), Aggregation (aggregation), Composition (composition). Among them, Aggregation (aggregation) and Composition (synthesis) belong to Association (association), which is a special Association association.
1. Dependency relationship
Dependency (Dependency) is a kind of usage relationship, the change of a particular thing may affect other things that use that thing, and use dependency relationship when it is necessary to indicate that one thing uses another thing. In most cases, dependencies are reflected in the fact that a method of one class takes an object of another class as a parameter.
Relationship: dependency is used to indicate the compliance relationship between the two, as use a.
In UML, dependencies are represented by dotted lines with arrows, pointing from the dependent party to the dependent party.
Class channle {public: play () {cout
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.