A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service
Object-oriented (OO) is currently the focus of the computer industry, and is the mainstream of software development methods in 1990s. Object-oriented concepts and applications have gone beyond programming and software development and have been extended to a wide range. Such as database systems, interactive interfaces, application structures, application platforms, distributed systems, network management structures, CAD technology, artificial intelligence, and other fields.
There are many articles about object-oriented. However, the definition of objects is clearly given or the definition of objects is very small-at least I have not found it yet. At first, "object-oriented" refers to the use of encapsulation, inheritance, abstraction, and other design methods in program design. However, this definition is obviously not suitable for the current situation. Object-oriented thinking involves various aspects of software development. For example, object-oriented analysis (OOA, Object Oriented Analysis), object-oriented design (OOD, object oriented design), and object-oriented programming implementation (OOP, object Oriented Programming ). Many articles about object-oriented are only about the issues that need to be paid attention to in object-oriented development or the better design methods used. Only by understanding what objects are and what object orientation is, can these articles help you to the greatest extent. I am afraid that the concepts of beginners and even those who have been engaged in related work for many years will be vague.
[Edit this section] I. Problems with traditional development methods
1. Poor software reusability
Reusability refers to the repeat of a single thing without modification or slight modification. Software reusability is one of the goals of software engineering.
2. Poor Software maintainability
Software Engineering emphasizes Software maintainability and the importance of documents, and stipulates that the final software product should be composed of complete and consistent configuration components. During software development, software readability, modification, and testability are always emphasized as important quality indicators of the software. Practice has proved that the maintenance cost and cost of software developed using traditional methods are still very high because of poor modification and maintenance, resulting in poor maintainability.
3. The developed software cannot meet user needs.
Using traditional structured methods to develop large-scale software systems involves knowledge in different fields. When developing systems with vague requirements or dynamically changing requirements, the developed software system often cannot meet the needs of users.
The stability, modifyability, and reusability of software developed using structured methods are poor. This is because structured methods are essentially functional decomposition, starting with a single process that represents the overall functions of the target system, from top to bottom, we constantly break down complex processing into sub-processing, so that layer-by-layer decomposition will continue until there are only a few sub-processing functions that are easy to implement, then, the corresponding tools are used to describe the processing of each lowest layer. Therefore, the structured method constructs the system around the "process" to implement the processing function. However, most of the changes in user requirements are for functions. Therefore, such changes are disastrous for process-based design. The system structure designed using this method is often unstable. Changes in user requirements often result in large changes in the system structure, which requires a large cost to achieve this change.
[Edit this section] 2. Basic object-oriented concepts
Objects are all things that people need to study. From the simplest integer to the complex aircraft, they can be regarded as objects. They can not only represent specific things, it can also represent abstract rules, plans, or events.
(2) object status and behavior.
An object has a state, and a data value is used to describe its State.
The object also has operations to change the object state. The object and its operations are the behavior of the object.
Objects combine data and operations to encapsulate data and operations in the unity of objects.
Abstract objects of the same or similar nature are classes. Therefore, the object is abstracted as a class, and the class is embodied as an object. It can also be said that the instance of the class is an object.
A class has attributes. It is an abstraction of the object state and describes the attributes of a class using a data structure.
The class has operations. It is the abstraction of the object's behavior. It is described by the Operation name and the method to implement this operation.
(4) class structure.
There are several classes in the objective world, which have some structural relationships. There are usually two main structural relationships: general-specific structural relationships, and overall-partial structural relationships.
① General: the specific structure is called the classification structure. It can also be called the "or" relation, or the "is a" link.
② Whole-some structures are called assembly structures, and the relationship between them is a kind of "and" relationship, or "has a" relationship.
(5) messages and methods.
The structure for communication between objects is called message. In an object operation, when a message is sent to an object, the message contains the information of the recipient performing an operation. To send a message, you must at least specify the name of the object that receives the message and the name of the message sent to the object (that is, the object name and method name ). It is also necessary to describe the parameters. The parameters can be the names of variables known to the objects that know the message, or the names of global variables that all objects know.
The implementation process of operations in a class is called a method. A method includes a method name, a parameter, and a method body.
[Edit this section] 3. Object-oriented features
(1) uniqueness of an object.
Each object has its own unique identifier. Through this identifier, you can find the corresponding object. During the entire lifecycle of an object, its identifier remains unchanged. Different objects cannot have the same identifier.
Classification refers to abstracting objects with consistent data structures (attributes) and actions (Operations) into classes. A class is such an abstraction, which reflects the important properties related to the application and ignores other irrelevant content. The division of any class is subjective, but it must be related to specific applications.
Inheritance is the mechanism by which child classes automatically share parent class data structures and methods. This is a relationship between classes. When defining and implementing a class, you can base on an existing class and take the content defined by this existing class as your own content, and add some new content.
Inheritance is the most important feature of object-oriented programming languages different from other languages and is not available in other languages.
In the class hierarchy, a subclass inherits only the data structure and method of a parent class, which is called Single-re-inheritance.
In the class hierarchy, child classes inherit the data structures and methods of multiple parent classes, which are called multi-inheritance.
In software development, the inheritance of classes makes the software open and scalable. This is an effective method for information organization and classification. It simplifies the workload of object and class creation, added code reusability.
Inheritance is used to provide a standard class level structure. Through the inheritance relationship of classes, public features can be shared, improving the reusability of software.
(4) polymorphism (polymorphism)
Polymorphism means that the same operation, function, and process can act on multiple types of objects and obtain different results. Different objects receive the same message to produce different results. This phenomenon is called polymorphism.
Polymorphism allows each object to respond to common messages in a suitable way.
Polymorphism enhances software flexibility and reusability.
[Edit this section] 4. Object-oriented Elements
Abstract refers to emphasizing the essence and inherent attributes of an object. In system development, abstraction refers to the meaning and behavior of objects before deciding how to implement objects. Using abstraction can avoid premature consideration of some details.
Class implements the abstraction of object data (that is, State) and behavior.
(2) Encapsulation (Information Hiding ).
Encapsulation is the basis for ensuring excellent controllability of software components.
Object-oriented classes are well-encapsulated modules. class definitions explicitly separate their descriptions (User-visible external interfaces) from implementations (User-invisible internal implementations, its internal implementation provides protection according to its specific scope.
Objects are the most basic unit of encapsulation. Encapsulation prevents changes caused by program dependency. Object-oriented encapsulation is clearer and more powerful than traditional language encapsulation.
Object-oriented technology promotes sharing at different levels
Share in the same class. Objects in the same class have the same data structure. These objects share structures and behavioral features.
Shared in the same application. In the class hierarchy of the same application, similar sub-classes with inheritance relationships exist, and data structures and behavior inheritance exist, so that similar sub-classes share the common structure and behavior. Using inheritance to share code is also one of the main advantages of object-oriented.
Shared among different applications. Object-oriented not only allows sharing information in the same application, but also provides conditions for reusable designs for future goals. The library mechanism and structure are used to share information in different applications.
4. Emphasize the object structure rather than the program structure
Iv. object-oriented development methods
At present, the research on object-oriented development methods has become increasingly mature, and many international object-oriented products have emerged. Object-Oriented development methods include Coad, booch, and OMT.
1. booch Method
Booch first describes the basic issues of object-oriented software development methods, and points out that object-oriented development is a design method that is fundamentally different from traditional functional decomposition. Object-Oriented Software decomposition is closer to people's understanding of objective transactions, while functional decomposition is obtained only through the conversion of problem spaces.
2. Coad Method
The Coad method is an object-oriented development method proposed by Coad and Yourdon in 1989. The main advantage of this method is that through years of experience in large-scale system development and the combination of object-oriented concepts, a set of system principles are proposed in the identification of objects, structures, attributes and operations. This method further identifies the class and class hierarchy from the perspective of requirements. Although the Coad method does not introduce the terms of Class and Class hierarchies, in fact, it has embodied the characteristics of Class and Class hierarchies in the concepts of classification structure, attributes, operations, and message Association.
3. OMT Method
The OMT method was proposed by James Rumbaugh and other five people in 1991. Its classic book is "Object-Oriented Modeling and design ".
This method is a new object-oriented development method. The basis of the development work is to model objects in the real world, and then use analysis models to design language-independent objects, object-Oriented Modeling and design promotes understanding of requirements and facilitates the development of software systems that are clearer and easier to maintain. This method provides a practical and efficient guarantee for software development in most application fields, and strives to find a practical solution to the problem.
4. UML (Unified Modeling Language) Language
Software Engineering in 1995 ~ In 1997, unprecedented progress was made, surpassing the total achievements in the software engineering field over the past 15 years. One of the most important achievements is the emergence of a Unified Modeling Language (UML. UML will be the leading standard modeling language in the field of object-oriented technology.
UML not only unifies the Expression Methods of booch, OMT, and OOSE methods, but also makes further development on it, and finally unified it into a standard modeling language accepted by the masses. UML is a well-defined, easy-to-Express, powerful, and universally applicable modeling language. It integrates new ideas, new methods, and new technologies in the software engineering field. Its scope is not limited to support object-oriented analysis and design, but also the entire process of software development starting from requirement analysis.
[Edit this section] 5. object-oriented model
· Object Model
The object model represents the static and structured nature of system data and describes the static structure of the system. It describes the Object Relationships of objects in the objective world. This model focuses on the structure, attributes, and operations of objects in the system. It is the core of the three models in the analysis phase and the framework of the other two models.
1. Objects and Classes
Object Modeling aims to describe objects.
By abstracting objects into classes, we can abstract the problem and abstract it to enhance the model induction capability.
Attribute refers to the Nature (data value) of objects in the class ).
(4) operations and methods.
An operation is a function or transformation used by objects in a class. Objects in the class can share the operation, and each operation has a target object as its implicit parameter.
Methods are the implementation steps of class operations.
2. Association and chain
Association is a means to establish relationships between classes, while chain is a means to establish relationships between objects.
(1) Meaning of association and chain.
A chain represents the physical and conceptual connections between objects, and a link represents a relationship between classes. A chain is an associated instance, and a link is an abstract chain.
Role description the role of a class in association. It is located at the associated endpoint.
(3) Restricted Association.
Restricted associations are composed of two classes and one restricted word. A restricted word is a specific attribute used to effectively reduce the number of associated duplicates. The Restricted word is described in the correlated terminal object set.
Limitation improves the semantic accuracy and query capability. In the real world, there are often restrictions.
(4) Multiple associations.
Multiple associations refer to how many objects in a class are related to an object of the associated class. The number of duplicates is often described as "one" or "multiple ".
3. Hierarchy of Classes
(1) clustering relationship.
Clustering is a "Whole-part" relationship. In this relationship, there are two types: Overall class and partial class. The most important property of clustering is the transmission and Inverse symmetry.
Clustering can have different levels, and different classifications can be aggregated to form a simple clustering tree. Clustering tree is a simple representation, which is much easier than drawing many lines to associate partial classification, the object model should easily reflect all levels.
(2) general relationship.
Generalized relationships are highly abstract methods that Share Object similarity while retaining object differences. It is a "general-specific" relationship. A generalized class is called your class. A specific class can also be called a subclass. each subclass inherits the properties of the class, and some common properties and operations of each subclass are summarized into your class. Therefore, General relationships and inheritance exist simultaneously. The symbol of the generalized link indicates that a small triangle is added to the link of the class association.
4. Object Model
(1) template. Templates are logical components of classes, associations, and general structures.
(2) object model.
An object model consists of one or more templates. The template divides the model into several child blocks that are easy to manage. The template provides an integrated intermediate unit between the entire object model, class, and associated construction blocks, the class name and association name in the template are unique.
· Dynamic Model
Dynamic models are system properties related to time and change. This model describes the control structure of the system. It represents instantaneous and behavioral system control.
It is concerned with the control of the system and the execution sequence of operations. It represents the mutual behavior of objects from the perspective of Object events and States.
The system attributes described in this model are the organizations that trigger events, event sequences, States, events, and States. Use the status chart as the description tool. It involves important concepts such as events, status, and operations.
An event occurs at a specified time.
State is the abstraction of object property values. The attribute values of an object are merged into a state based on the properties that affect the significant behavior of the object. Status indicates the object
Response to the input event.
3. status chart
A state chart is a standard computer concept. It is a graphical representation of Finite Automation. The state chart is used as a graphical tool for creating dynamic models.
The status chart reflects the relationship between the status and the event. When an event is received, the next state depends on the current state and the event received. The state changes caused by this event are called conversions.
A status chart is a chart that uses nodes to represent the State and nodes to represent the State. A status name exists in the circle and an arrow link is used to represent the state transition. The event name is marked above, the arrow direction indicates the direction of conversion.
· Functional model
The function model describes all calculations of the system. The functional model specifies what happens, the dynamic model determines when, and the object model determines the object that occurs. The function model shows how to calculate the input value to the output value without considering the order of calculation. The function model consists of multiple data streams. A data flow chart is used to represent the flow of data values from the source object to the target object. It does not contain control information, and control information is expressed in a dynamic model. A data flow chart does not represent the organization of the objects, the value is organized in the object model. Figure 10-15 shows the data flow chart displayed by the icon of a window system.
A Data Flow chart contains processing, data flow, Action object, and data storage object.
The processing in the data flow chart is used to change the data value. The lowest layer processing is purely a function, and a complete data flow diagram is a high-level processing.
2. Data Stream
The data flow in the data flow diagram associates the output and processing of objects with the input, processing and processing of objects. In a computer, data streams are used to represent the data values in a single middle. Data Streams cannot change the data values.
3. Action object
An action object is an active object that generates or uses data values to drive a data flow chart.
4. Data storage objects
Data storage in a data flow chart is a passive object used to store data. Unlike the action object, data storage does not produce any operations. It only responds to the requirements of storage and access.
[Edit this section] 6. Object-Oriented Analysis
Object-Oriented Analysis Aims to model systems in the objective world. Based on the model concepts described above, this section constructs an accurate and rigorous analysis model for objective world problems based on the specific instance of the "banking network system.
The analysis model has three purposes: to clarify the problem requirements, to provide users and developers with clear requirements, to provide users and developers with a basis for negotiation, as a subsequent design and implementation framework.
(1) Object-Oriented Analysis
The first step in system analysis is to state the requirements. The analyst must work with the user to extract the demand, because this shows the real intention of the user, which involves analyzing the demand and searching for lost information. The following uses the "banking network system" as an example to develop it using the object-oriented method.
Bank Network System Problem description: The software is designed to support the bank network. The banking network includes the automatic Cashier Machine shared by the manual cashier station and the branch. Each branch office uses the computer of the branch office to store their respective accounts and handle their respective affairs. The cashier Station of the respective branch office communicates with the computer of the branch office, and the cashier station enters account and transaction data; the automatic cashier machine communicates with the computer of the Branch, the computer of the Branch and the appropriation branch settle the bill, the automatic Cashier Machine accepts cash cards with the user interface, communicates with the computer of the Branch to complete the transaction, issue the cash, and print the receipt; the system must record the storage and security measures. The system must correctly process concurrent access to the same account. Each sub-processing prepares software for its own computer, bank network fees are distributed to the branches based on the number of customers and cash cards.
Figure 10-18 shows the banking network system.
(2) create an object model
First, identify and associate, because they affect the overall structure and Solution to the Problem. Second, add attributes to further describe the class and associated basic network, and use the inherited merge and organizational classes, finally, the operation is added to the class as a by-product to construct the dynamic model and functional model.
1. Determine the class
The first step to construct an object model is to mark the relevant object classes from the problem domain. objects include physical entities and concepts. All classes must be meaningful in the application. In the problem statement, not all classes are clearly given. Some are hidden in the problem domain or general knowledge.
Determine the class according to the process shown in Figure 10-19
Find all the nouns in the problem statement and generate the following tentative classes.
Software Bank Network cashier automatic cashier Branch
Sub-processing computer account transaction cashier Station
Transaction data branch computer cash card user cash
Receipt system customer expense account data
Secure Access Security Measure records
Remove unnecessary classes and incorrect classes according to the following criteria.
(1) redundancy class: if the two classes express the same information, the class with the highest descriptive ability is retained. For example, "user" and "customer" are repeated descriptions, because "customer" is the most descriptive, so it is retained.
(2) irrelevant classes: Remove classes that are irrelevant to the problem or are not at all. For example, the fee is out of the bank network.
(3) fuzzy class: the class must be definite. Some tentative class boundary definitions are vague or the scope is too wide. For example, "record keeping" is a fuzzy class, which is a part of "transaction.
(4) attribute: if some nouns describe the attributes of other objects, they are deleted from the tentative class. If the independence of a certain nature is very important, it should be attributed to the class rather than as an attribute.
(5) operation: If the nouns in the problem statement have action meanings, the operation described is not a class. However, operations that have their own nature and require independent existence should be described as classes. For example, if we only construct the telephone model, "dialing" is part of the dynamic model, not a class. However, in the Telephone Dialing system, "dialing" is an important class, date, time, location, and other attributes.
In the banking network system, fuzzy classification includes "system", "Security Measures", "record keeping", and "banking network. The attributes include "account data", "receipt", "cash", and "transaction data ". Such as "access" and "software. These should be removed.
2. Prepare a data dictionary
Prepare a data dictionary for all modeling entities. Accurately describe the exact meaning of each class, and describe the scope of the class in the current problem, including assumptions or restrictions on the class members and usage.
3. Confirm Association
The dependency between two or more classes is Association. A dependency indicates an association, which can be implemented in various ways. However, you must delete the Implementation Considerations in the analysis model to make the design more flexible. Commonly used descriptive verbs or verb phrases are associated to indicate physical locations, transmitted actions, communications, owner relationships, and conditions. Extract all possible association statements from the problem statement and write them down, but do not refine them too early.
Below are all possible associations in the banking network system, most of which are obtained by directly extracting the verb phrases in the problem. In a statement, the association between verb phrases is not obvious. Finally, some associations are related to the objective world or people's assumptions and must be verified with the user, because such associations cannot be found in the problem statement.
Association in Bank Network Problem Statement:
· The bank network includes the cashier station and automatic Cashier Machine;
· Branches share automatic cashiers;
· The Branch Office provides the branch office computer;
· The computer saving account of the branch office;
· The branch office computer handles account payment transactions;
· The branch office has a cashier station;
· The cashier station communicates with the computer of the branch office;
· The cashier enters transactions for the account;
· The automatic cashier receives cash cards;
· Automatic cashier and user interface;
· Automatic cashier issuing cash;
· The automatic cashier prints the receipt;
· The system processes concurrent access;
· The branch offices provide software;
· Fees are distributed to the branch offices.
Implicit Verb Phrase:
· A branch is composed of branch offices;
· Accounts owned by the branch offices;
· The Branch owns branch computers;
· The system provides record keeping;
· The system provides security;
· Customers have cash cards.
Association Based on question domain knowledge:
· The Branch Office employs cashiers;
· Cash card access account.
Remove unnecessary and incorrect associations using the following criteria:
(1) If a class has been deleted, its associated associations must also be deleted or re-expressed using other classes. In this example, we have deleted the "banking network" and deleted the related associations.
(2) unrelated association or implementation phase association: deletes any association outside the problem domain or involves Association in the implementation structure. For example, "system processing concurrent access" is an implementation concept.
(3) Action: The Association should describe the structure nature of the application domain, rather than the instantaneous event. Therefore, delete "automatic cashier accepting cash card" and "automatic cashier and user interface.
(4) derivative Association: omitting the associations that can be defined by other associations. This association is redundant. Figure 10-20 shows the initial object of the banking network system. It contains associations.
4. Confirm attributes
Attribute is the nature of an individual object. attributes are usually represented by modifier nouns and phrases. adjectives often indicate specific enumerated attribute values. Attributes cannot be fully expressed in the problem statement. They must be found by applying domain knowledge and knowledge of the objective world. Only attributes directly related to specific applications are considered, and those attributes beyond the scope of the problem are not considered. First, find out the important attributes to avoid those attributes that are only used for implementation and take meaningful names for each attribute. Remove unnecessary and incorrect properties according to the following criteria:
(1) object: If the independent existence of an object is more important than its value, the object is not an attribute but an object. For example, in the zip directory, "city" is an attribute, but in the census, "city" is regarded as an object. In a specific application, an object of its own nature must be an object.
(2) fixed term: If the attribute value depends on a specific context, you can reexpress this attribute as a qualified term.
(3) Name: A name is often used as a qualifier rather than an object attribute. When a name does not depend on context, it is an object attribute, especially when it is not only temporary.
(4) identifier: when considering the ambiguity of an object, object identifiers are introduced to indicate that these object identifiers are not listed in the object model. They are hidden in the object model, only attributes that exist in the application domain are listed.
(5) Internal Value: If the attribute describes the internal status of an object that is not transparent to the outside, the attribute should be deleted from the object model.
(6) refinement: Ignore attributes that cannot affect most operations.
5. Use inheritance to refine the class
Inheritance can be used to share public institutions and organize classes in the same way.
(1) from the bottom up, we can generalize the common nature of existing classes as parent classes and find classes with similar attributes, relationships, or operations to discover inheritance. For example, "remote transactions" and "cashier transactions" are similar and can be generalized to "transactions ". Some general structures are often existing classifications based on objective world boundaries. If possible, try to use existing concepts. Symmetry often helps to find some lost classes.
(2) refine the existing classes into more specific child classes from top to bottom. It is often apparent from the application domain that specific objects are made. Enumerative characters in the application domain are the most common sources of specific characters. For example, a menu can have fixed menus, top menus, pop-up menus, and drop-down menus. This allows you to refine the menu class into sub-classes of various menus. When the same association name appears multiple times and the meaning is the same, it should be embodied as the associated class as much as possible, for example, "transaction" enters from "cashier Station" and "automatic cashier, then "entry Station" is the generalization of "cashier Station" and "automatic cashier station. At the class level, you can assign attributes and associations to specific classes. Each attribute and attribute should be assigned to the most suitable class, and sometimes some corrections are added.
Enumeration in the application domain is the most common concrete source.
6. Improved the Object Model
Object Modeling cannot ensure that the model is completely correct once. The entire process of software development is a process of continuous improvement. Different components of a model are mostly completed in different stages. If a model defect is found, it must be returned to the preliminary stage for modification, some refinement work starts only after the dynamic model and functional model are completed.
(1) possible loss of objects and solutions:
· If there are non-relational attributes and operations in the same class, the class will be broken down to associate each part;
· If the general system is unclear, classes playing two roles may be separated.
· If there is an operation with no target class, find and add the class with the loss of the target;
· If redundant associations with the same name and purpose exist, the lost parent class is created in generalization to organize the associations together.
(2) Search for unnecessary classes.
You can delete this class if the class does not contain attributes, operations, and associations.
(3) search for lost associations.
If the access path of the operation is lost, add a new association to answer the query.
(4) modify the network system as follows:
① Cash cards have multiple independent features. It is divided into two objects: Card permission and cash card.
A. card permission: A card used by a bank to identify user access permissions, indicating the access permissions of one or more user accounts. Each card permission object may have several cash cards, each card carries a security code and card code. They are attached to a cash card to indicate the bank's card permissions.
B. Cash card: it is a data card for the automatic cashier to get the Expression Code. It is also the data carrier of the bank code and cash card code.
② "Transaction" does not indicate the general description of the transfer between accounts, because it only involves one account. Generally, in each account, A "transaction" includes one or more "Updates", and an "Update" is an action to the account. They are one of the withdrawals, deposits, and queries. All "Updates" in an "Update" should be an atomic operation.
③ The difference between "branch office" and "separate processor" and "branch processor" does not seem to affect analysis. Computer Communication processing is actually a concept of implementation, merge the "branch computer" into the "branch computer", and merge the "branch computer" into the "branch ".
(3) Establishing a Dynamic Model
1. Prepare the script
Dynamic analysis starts from searching for events, and then determines the sequence of possible events of each object. In the analysis phase, algorithm execution is not considered. algorithms are part of the implementation model.
2. Confirm the event
Determine all external events. Events include all information from or sent to users, signals from external devices, input, conversion, and actions. Normal events can be found, but conditions and exceptions cannot be missed.
3. Prepare an event tracking table
The script is represented as an event tracking table, that is, an event sorting table between different objects. The object is a column in the table and an independent column is assigned to each object.
4. Construct a state chart
Create a status chart for each object class to reflect the events received and sent by the object. Each event trace corresponds to a path in the status chart.
(4) build functional modeling
The function model is used to describe how a value is calculated, to indicate the dependencies between values and related functions. A data flow chart helps to indicate functional dependencies, and the processing of such dependencies is based on the activities and actions in the status chart, the data stream corresponds to the object or attribute in the object graph.
1. Determine the input and output values
Lists input and output values first. input and output values are parameters of events between the system and the outside world.
2. Create a data flow chart
The data flow diagram shows how the output value comes from the input value. The data flow diagram is usually organized by layer.
(5) confirm the operation
Classes, associations, structures, and attributes are determined when an object model is created, and operations are not yet determined. Class operations can be finalized only after a dynamic model and a functional model are created.
[Edit this section] VII. Object-oriented Design
Object-Oriented Design refers to the process of converting the requirements obtained in the analysis stage into an abstract system implementation solution that meets cost and quality requirements. From Object-Oriented Analysis to object-oriented design, it is a process of gradually expanding the model.
The waterfall model further divides the design into two phases: Outline Design and detailed design. Similarly, the object-oriented design can be subdivided into System Design and Object design. The system design determines the strategy for implementing the system and the high-level structure of the target system. Object design determines the classes, associations, interface forms, and Algorithm for implementing operations in the solution space.
(1) Guidelines for Object-Oriented Design
The object-oriented development method naturally supports the design principle of decomposing the system into modules: the object is the module. It is a module that closely integrates the data structure and the methods used to operate the data.
Object-oriented methods not only support process abstraction, but also support data abstraction.
3. Information Hiding
In object-oriented methods, information hiding is achieved through object encapsulation.
4. Low Coupling
Objects are the most basic modules in object-oriented methods. Therefore, coupling mainly refers to the closeness of different objects. Low coupling is an important design standard because it helps minimize the impact of changes in a part of the system on other parts.
5. High Cohesion
(1) Operation Cohesion.
(2) class cohesion.
(3) General-specific cohesion.
(2) Incentive rules for Object-Oriented Design
1. the design results should be clear and easy to understand
Making the design results clear, easy to understand, and easy to read is an important measure to improve Software maintainability and reusability. Obviously, people will not reuse designs they don't understand.
To do this:
(1) use the same words.
(2) Use existing protocols.
(3) Reduce the number of message modes.
(4) Avoid fuzzy definition.
2. General-the depth of the specific structure should be appropriate
3. Simple Design
Design small and simple classes as much as possible to facilitate development and management. Pay attention to the following points for simplicity:
(1) avoid too many attributes.
(2) There are clear definitions.
(3) try to simplify the cooperative relationship between objects.
(4) do not provide too many operations.
4. Use simple protocols
Generally, the number of parameters in a message must not exceed 3.
5. Simple operations
The operations in the class designed by the object-oriented method are usually very small. Generally, there are only three to five source program statements. You can use a simple sentence containing only one verb and one object to describe its function.
6. Minimize design changes
Generally, the higher the design quality, the longer the design results remain unchanged. Even if the design must be modified, the modification scope should be as small as possible.
(3) System Design
System design is an advanced strategy for solving problems and establishing solutions. You must develop basic solutions to the problem, the system's high-level structure includes subsystem decomposition, inherent concurrency, distribution of subsystems to hardware and software, data storage management, resource coordination, software control implementation, and human-computer interaction interfaces.
1. system design overview
In the design phase, we should first start with the high level and then refine it. System design determines the entire structure and style. This structure provides a foundation for the design of more detailed policies in the design phase.
(1) system decomposition.
The main component of a system is called a subsystem. A subsystem is neither an object nor a function, but a set of classes, associations, operations, events, and constraints.
(2) Determine concurrency.
Many objects in the analysis model, real world, and hardware are concurrent.
(3) processor and task allocation.
Each concurrent subsystem must be assigned to a single hardware unit, either a general processor or a specific functional unit.
(4) Data Storage Management.
Storage and management of internal and external data in the system is an important task. Generally, data storage can combine data structures, files, and databases. Different data storage requires a compromise between costs, access time, capacity, and reliability.
(5) Processing of global resources.
You must determine global resources and create a policy to access global resources.
(6) Select the software control mechanism.
All InterAction behaviors in the analysis model are represented as events between objects. System design must select a method from multiple methods to implement software control.
(7) human-computer interaction interface design.
Most of the work in the design is related to stable state behavior, but you must consider using the interactive interface of the system.
2. General framework of System Structure
3. System Decomposition-establish the system architecture
Available software libraries and programming experience of programmers.
The precise problem domain model obtained through object-oriented analysis lays a good foundation for designing the architecture and establishes a complete framework.
4. Select software control mechanism
There are two types of control flows in the software system: external control flows and internal control flows.
5. Data Storage Management
Data storage management is the basic facility for system storage or retrieval objects. It is built on a data storage management system and isolates the impact of the data storage management mode.
6. Design Human-Computer Interaction Interfaces
In the process of object-oriented analysis, the user interface requirements have been preliminarily analyzed. In the process of object-oriented design, the human-computer interaction interface of the system should be designed in detail, to determine the details of human-computer interaction, including the format of the specified window and report, and the design command level.
(4) Object Design
1. Object design overview
2. Combination of the three models
(1) obtain the operation.
(2) determine the target object of the operation.
3. Algorithm Design
4. Optimized Design
5. Implementation of control
6. Adjust inheritance
7. Associated Design
[Edit this section] 8. Object-oriented implementation
(1) Programming Language
1. Select object-oriented language
The basic purpose and main advantage of using object-oriented method to develop software is to improve software productivity through reuse. Therefore, we should give priority to the object-oriented language that is the most perfect and accurate expression of question domain semantics.
When selecting a programming language, other factors should be taken into account: training operations that can be provided by user learning object-oriented analysis, design, and coding techniques; the technical support that can be provided during the use of this object-oriented language; the development tools and development platforms that can be provided to developers, the requirements for machine performance and memory, and the ease of integrating existing software.
2. programming style
(1) improve reusability.
(2) Improve scalability.
(3) improve robustness.
(2) Implementation of Classes
In the development process, class implementation is the core issue. In a system written in an object-oriented style, all data is encapsulated in a class instance. The entire program is encapsulated in a more advanced class. In an object-oriented system with existing parts, software can be implemented with only a small amount of time and effort. You only need to add a class instance, develop a small number of new classes, and implement the communication between objects, you can build the required software.
One solution is to first develop a relatively small and relatively simple program, which serves as the basis for developing large and complex classes.
(1) "intact" reuse.
(2) evolutionary reuse.
A class that fully complies with the required features may not exist.
(3) "obsolete" development.
There is no need to reuse it to develop a new class.
(4) handle errors.
A class should be autonomous and have the responsibility to locate and report errors.
(3) Implementation of the application system
The implementation of the application system is after all classes are implemented. Implementing a system is a simpler and shorter process than using procedural methods. Some instances will be used during initialization of other classes. The rest must be explicitly described using a main process, or as part of the representation of the class at the highest level of the system.
There is a main () function in C ++ and C. You can use this process to describe the instances of the classes that constitute the main objects of the system.
(4) Object-oriented Testing
(1) algorithm layer.
(2) Class layer.
Test the interaction between all methods and attributes encapsulated in the same class.
(3) template layer.
Test the interaction between a group of collaborative classes.
(4) system layer.
The subsystems are assembled into a complete object-oriented software system and tested simultaneously during the assembly process.
[Edit this section] IX. Differences between object-oriented and Object-based
Many people do not distinguish between "Object-Oriented" and "Object-based. The three characteristics of object-oriented (encapsulation, inheritance, and polymorphism) are indispensable. Objects are usually used based on objects, but existing Object Templates cannot be used to generate new object types and generate new objects. That is to say, objects are not inherited. "Polymorphism" indicates a subclass object instance of the parent class. Without the concept of inheritance, there is no way to talk about "polymorphism ". Nowadays, many popular technologies are based on objects. They use encapsulated objects, call object methods, and set object attributes. However, they cannot allow programmers to derive new object types. They can only use methods and attributes of existing objects. So when you determine whether a new technology is object-oriented, you can usually use the last two features to determine. Both "Object-Oriented" and "Object-based" implement the concept of "encapsulation", but object-oriented implements "inheritance and polymorphism", while "Object-based" does not, indeed, it is very good.
People engaged in object-oriented programming can be divided into class library creators and class library users by division of labor ". Not all people who use the class library have the idea of object-oriented. They usually know how to inherit and derive new objects to use the class library. However, our thinking has not really been transferred, class Libraries are only object-oriented in form, but essentially an extension of library functions.
Object-oriented is an idea. It is a method for us to consider things. It usually shows that we solve the problem according to the process, or abstract the problem into an object to solve it. In many cases, we will solve the problem through the process without knowing it, instead of abstracting the problem to be solved as an object to solve it. Some people are doing process programming under the guise of object-oriented
[Edit this section] 10. Object-oriented example
Here we will use a specific instance to understand its encapsulation! In the object-oriented method
Objects can be viewed as attributes (data) and encapsulation bodies of special operations on these attributes.
Encapsulation is an information shielding technique, which aims to separate object definitions and implementations.
1.1 create a project named vboop;
1.2 click the project menu, select Add class module, and click OK;
1.3 In the Properties window, change the class name to tscore.
Step 2: edit the code of the tscore class module
. Here, four private variables are defined for the tscore class. They can only be used in this module.
Is visible, that is, some members of the class are hidden, and the user can only use the attribute Process
Or functions to encapsulate objects.
Basic syntax for defining variables:
Private fname as string/'Student name
Private fmath as single/'mathematical score
Private fenglish as single/'English score
2. Define six public attributes for the tscore class and
Total number of calculation methods and functions.
Basic syntax for defining methods:
Private/publc property get;
Private/public property let (byval variable name as return value type );
Get: Assign the value of the private variable in the module to the attribute process, which is usually called read;
Let: Assign the private variable value in the module through the attribute process, which is usually called write.
Public property get getname () as string
Getname = fname
Public property let setname (byval name as string)
Fname = Name
Public property get getmath () as single
Getmath = fmath
Public property let setmath (byval math as Single)
Fmath = math
Public property get getenglish () as single
Getenglish = fenglish
Public property let setenglish (byval English as Single)
Fenglish = English
Public Function total () as single/'calculates the total score function
Total = getmath + getenglish
Step 3: Return to the form1 window and add 12 controls to the window:
3.1 add five text boxes: txtname, txtmath, txten, and txttotal;
3.2 add 5 labels labname, labmath, laben, and labtotal.
The caption attributes are name, mathematics, English, and total score;
3.3 Add two command buttons comsetvalues and comsearch
The caption attributes are assigned and queried respectively.
Step 4: edit window events
. Construct the score object and query keyword searchkey. In the object-oriented method
, We can say that the definition class is to define the data type, and declare
Such as declaring variables. That is to say, the object is actually a variable.
Dim score as new tscore
Dim searchkey as string
. Click events that assign values to four private variables in the module
Private sub comsetvalues_click ()
If Val (txtmath. Text)> = 0 and Val (txtmath. Text) = 0 and Val (txten. Text)
Start building with 50+ products and up to 12 months usage for Elastic Compute Service