Analysis business model-class digraphs (lower)

Source: Internet
Author: User

Summary:Class Diagram(Class digoal) is probably the most commonly used one.UMLGraph. The basic syntax of a class chart is not complex. You may be able to master it for a maximum of two or three days. However, it may take several years to truly use a class chart. Class diagrams are an important tool for training the ideas of Object-Oriented Analysis (OOA: object-oriented analysis) and object-oriented design (OOD: object-oriented design, it is an important tool for business structure modeling. This chapter will have a lot of practical exercises, and your OOA thinking will be greatly tested and improved.

This article has a total length of more than 10 thousand characters and dozens of illustrations. Due to the length constraints, this article is divided into the first and second articles.
This article is from Chapter 3rd of the new book "use UML-demand analysis experts.

Author: Zhang chuanbo
Www.umlonline.org

Outline:

Part 1:
3.1 process-oriented and object-oriented
3.2 Basic knowledge of class charts
Relationship between 3.3 classes
3.4 relationship between drill classes

Part II:
The "recursion" Relationship of the 3.5 class and the "Triangle" Relationship
3.6 Examination Management System-comprehensive training of class charts
3.7 object graph
3.8 summary and exercises

 

If you have not read the previous article, please read it first!

Link: http://www.cnblogs.com/umlonline/archive/2011/10/17/2215850.html

 

The "recursion" Relationship of the 3.5 class and the "Triangle" Relationship

 

This section isClass DiagramIt is a little difficult, but the knowledge isRequirement AnalysisWork is very practical.

Recursive relationship

My previous companyInterviewThere may be several hundred people. If the interviewer says that he understands the class chart, I will ask this question almost 100%: folders and files exist in the Windows operating system, use a class chart to show the relationship between folders and files.
After the previous study, you already have the basic knowledge to draw this graph. Please do not refer to the reference answers below and try to complete this question by yourself.
Many interviewers will soon draw such a picture:

Figure 1.30 relationship between folders and files 1

I will continue to ask these questions:
1) folders can also contain folders. How can this be expressed?
2) There may also be folders in the folder. What should I do?
Many interviewers are dumpfounded, and only a few can draw them.
In fact, I don't need to be discouraged when I can't draw a class chart. When I first learned a class chart, I was also overwhelmed by this question. Later I suddenly realized that I was looking at the answers and had a strange admiration for the class chart!

Figure 1.31 relationship between folders and files 2

There are folders in the folder, and there may be folders in the folder, which may be endless "recursion! This include relationship can point to itself, and can be "self-contained". This infinite "recursion" problem is solved, which is perfect!
Both weak and strongly contained data can be "self-contained ". In addition to "self-contained", "recursion" can be formed. In fact, linear relationships can also point to themselves. This is called "Self-Association", which also forms a "recursive" relationship. See:

Figure 1.32 auto-join

This "recursive" structure forms a tree structure once expanded. If you find a tree-type business structure during requirement analysis, you can use "self-contained" or "Self-Association" for analysis.
In fact, the "self-contained" and "self-Association" statements are not rigorous, but they are easy to remember and understand. In fact, a specific Folder does not contain its own. Here we need to further understand the meaning of each class in the class diagram. A class does not refer to a specific business object. A class generally refers to any business object of this class. The explanation here may not be clear enough. You can put it down now. Let's talk about this in the object graph section.

"Triangle" Relationship

The previous exercise asked you to draw the relationship between the company and its employees. Now, you are required to list at least three key attributes of the company and its employees respectively.
After listing the key attributes, consider the following:
1) is salary a key property of an employee? What about contract period and position?
2) How is the legal relationship between the company and its employees established?
You will surely think that the company and its employees need to sign a labor contract, and the labor contract includes the salary, contract period, and position, are salaries, contract periods, and positions still attributes of employees? What is the relationship between companies, employees, and labor contracts?

Figure 1.33 relationship between companies, employees, and labor contracts 1

On the straight line indicating the relationship between the company and its employees, pull out a dotted line and connect the other end to the labor contract class. Such a class is called the Association class ), an association class is a further constraint on the relationship between two classes.
In the beginning, you may think that salaries, positions, and contract periods should be the attributes of employees, but now you should realize that these three key elements should be reflected in the relationship between the company and its employees, these contents should be reflected in the labor contract. Further thinking, the employee's salary, position, and contract period will change. You may sign multiple labor contracts with the same company, there may also be multiple changes to the contract after a labor contract is signed.

It is difficult to identify the associated classes that can characterize the relationship between two classes. Some practical suggestions are provided for your reference:
1) if you think there is a relationship between the two classes, pull a straight line first.
2) if you think there is a relationship between the two classes, but you do not think this relationship is appropriate, you can think about whether an association class is missing.
3) list the key attributes of these two classes, and check whether the attribute values of these attributes are determined by the class itself. For example, if we use salary as an employee's attribute at the beginning, you can consider the specific salary number. Is it OK for the employee? You will find that the salary is determined by the company and the employee after the agreement, not the employee's own decision.
4) by thinking about attributes, you may find that this attribute belongs to another class and think about whether this class can represent the associated classes of the original two classes.

The customer is unlikely to tell you the complexity of association classes directly. You need to discover and extract association classes in demand analysis, this will be of great help to understand the requirements and design work in the later stage of the project.
It is not impossible to directly regard the salary, position, and contract period information as an employee's property, which is closely related to our system goals. If we only perform simple employee information management, there may be no need to extract the contract. If we want to implement a human affairs management system or even productization, We need to thoroughly analyze the business model.

Back to the previous "Organizational structure of the company" exercise, if we want to do a generalCompany ManagementSystem, we hope to adapt to different company situations as much as possible, then the extraction of the company's organizational structure in the example is necessary, if we can clearly understand the nature of the Company's Department architecture, then we can try to adapt to different situations as much as possible.
My practical suggestion is: in the demand analysis stage, we should try to thoroughly analyze the business, so that later work will be more active. When the business demand model turns into a design model, we can grasp the "degree" of design, make highly elastic design, or make a relatively "old-fashioned" design.
The relationships between companies, employees, and labor contracts can also be illustrated as follows:

Figure 1.34 relationship between companies, employees, and labor contracts 2

This figure may most reflect their "Triangle" relationship, and the association class can also be achieved in this way. However, in my actual work, I still express the association class. I think the expression of the association class is more appropriate and professional.
When analyzing specific requirements, if you find that the three classes form a "Triangle" relationship similar to the graph, you can think about whether a class may be an association class, however, it is important to note that there will not be any association class when there is a "Triangle" relationship.

How is it? The difficulty of this section has been increased to a tower!
The biggest charm of a class chart is that it helps you explore and extract business models.UMLThe graph may not be able to do so. Of course, if you really want to do a good job of exploration and refinement, you still need your profound skills!

In the next section, you will complete a comprehensive exercise to apply all the class diagrams you have learned.

 

3.6 Examination Management System-comprehensive training of class charts

 

This comprehensive exercise has the following purposes:
1) Let you consolidate what you have learnedClass DiagramKnowledge.
2) basic steps for analysis of drill requirements using class diagrams.
3) learn some new refining knowledge.

In this exercise, we will drill down the basic steps required for graph analysis:
1) Identify the class.
2) identify the main attributes of the class.
3) depicts the relationship between classes.
4) analyze, abstract, and organize various types of data.

The questions of this comprehensive training are as follows:
A school plans to develop an examination management system. The current situation is as follows:
1) The lecturer will talk about many courses. Most of the courses need to be arranged for an exam, which is not required in some cases.
2) The questions will be given by the instructors.
3) students need to take many tests and each test has scores.

Think about it:
1) is the exam a class? If so, what does the exam mean?
2) What are the classes directly related to the exam?
3) What is the relationship between the examination class and other classes?

This system is centered around the test. First, we need to determine what kind of examination is. Does the examination Class represent the examination paper? Or does it mean the exam? This is an exam management system, not an exam Management System (of course, the exam also needs to be managed in the system), and the exam needs to be managed, so the exam class represents the exam.
SetRequirement AnalysisIt is easy to recognize people, things, and concepts as classes. For things, such as exams, we may not recognize them as classes. It is generally believed that classes represent static things, and things are dynamic. Classes are not suitable for representation. This is not absolute, starting from the system's goal. Sometimes we need to identify some things, actions, and other dynamic content as a class. When we do a certain management system, and so-and-so refers to a thing, the system actually manages the thing by managing the records of the thing. For example, the examination management system actually manages the examination records. The leave management system actually manages the leave records. To make these things manageable, it is necessary to recognize these things as classes.

The significance of the examination class is basically determined. Its attributes include the examination time and place. Now we need to think about which classes are directly related to the examination? Are courses, exams, lecturers, scores, and students suitable?
First, list the classes directly related to the exam, and try to draw out the relationship between them and the exam, and then continue to look down.
Please note that you only need to find out the classes that are directly related to the examination, and do not need to find indirect ones. In addition, you only need to draw the relationship between other classes and the examination, do not consider the relationship between other classes.

Figure 1.35 relationship between the examination class and other classes

Note: This figure does not show the relationship between courses, lecturers, and students. This figure focuses on the relationship between other classes and examinations.

This figure shows the following situation:
1) Each course either has one exam or has no exam, and each exam corresponds to only one course.
2) one lecturer serves as the subject and corresponds to one or more tests, each of which has a corresponding teacher.
3) one student must take one or more tests, and one or more students must take one or more tests.
The score and exam should be highlighted.

As a student, he will get a score when taking one test, and he will get multiple scores when taking multiple tests, therefore, you can calculate the average score, highest score, and score ranking of the student. These contents can be listed as attributes of the student.
As for the test, many students take the test, so that this test will produce a lot of scores. Based on these scores, we can calculate the average score, the highest score, the excellent rate, and the pass rate of this test. Note that the average score and the highest score are also called the scores of this test. These scores can be listed as attributes of the test.
If the student's score ranking and the excellent rate of the exam are listed as attributes, these attributes can be "exported attributes", meaning the attributes calculated through other basic data. In requirement analysis, we need to focus on identifying basic attributes. basic attributes refer to "native" attributes, which are obtained directly without being calculated based on other things.

The score class defined in Figure 3.35 is the result of a student taking an exam. The score is native, the system can export many other statistics from the exam or student perspective.
After understanding the score class, it is easier to understand the exam class. An exam corresponds to a question teacher. The teacher designed a question for the exam, which is the exam.

The above is just a reference answer. There is no standard answer to this question. Identifying classes and drawing relationships between classes will lead to different results from different perspectives, the key is to start from the system's goals and make appropriate analysis. If your answer is inconsistent with the answer, it does not mean that you are not well drawn. As long as you can explain the relationship between these classes and them in a systematic manner, it is appropriate!

Through this comprehensive training process (rather than the results), we will summarize the following practical suggestions for your reference:
1) consider the problem from the perspective of the system.
2) The basic steps for analyzing requirements with a class chart: Identifying classes, recognizing attributes, drawing relationships, organizing and refining are just a general reference step.
3) identifying the key attributes of a class allows us to think about whether the class is suitable. Attempting to draw the relationship between classes also allows us to think about whether these classes are suitable.
4) read Multiple Graphs and read the relationship between the two classes in two directions. This helps you discover more problems.
5) you only need to express the direct relationship of the class. For example, a has a relationship with B, and B has a relationship with C. In this case, A and C are also related. They are indirectly related and do not need to be drawn directly, you only need to draw all the direct relationships. We can see the indirect relationships between classes through the relationship network of the class graph.
6) do not try to use a class chart to display all the content. The question of the examination system has actually been simplified a lot. There may be dozens or even hundreds of classes in the actual system class diagrams. You should plan to use multiple class diagrams to express different contents, each class chart has different expressions.
7) Identify "native" content, and do not use "exported content" as "Native content" based on these "native" content.
8) Identifying associated classes is a difficult and critical point. Separating associated classes will make us more aware of the nature of transactions.
9) if there is no absolutely correct answer, the key is to have your own rational analysis, Gradually refine and continuously optimize your ideas.
10) more exercises and discussions will gradually improve your Object-Oriented Analysis literacy.

 

3.7 object graph

 

WrittenCodeIt is easier for a friend to understand what an object is, and an instance of a class is an object ). Chapter 2UMLI have explained the object graph. Let's review it.
This is the person class:

Figure 1.36 person class

The following code instantiate the person class as a person object:
Person = new person ();
The object graph is displayed as follows:

Figure 1.37 person object

A company contains multiple employees.Class DiagramThis indicates:

Figure 1.38 relationship between companies and employees

The company and employees in this figure do not refer to the specific company or employee. If a company A has three employees, A, B, and C, they can be expressed as follows:

Figure 1.39 relationship between Company A and employees A, B, and C

"A: Company" indicates that object A is an instance of the company class; if it is ": Company", it indicates that this is an instance of the company class, but the specific name of this instance is not given.
Class is the abstraction or collective name of a certain type of things, while the object is a specific things. If Company A has 1000 employees, therefore, we need to draw one thousand "contained" to show the relationship between Company A and all employees. If there is a relationship between an object and an object, it must be a one-to-one relationship, because both are specific and cannot have a second one. For example, Zhang San and Li Si are good friends, and their relationship is a one-to-one relationship, because it is impossible for another Zhang San or Li Si. But if we Abstract Zhang San and Li Si as human beings, A person can make friends with many people, so that he can establish many-to-many friend relationships.
Requirement AnalysisIn fact, we are exposed to specific things, such as seeing specific people and accessing specific business data. These specific things are actually objects. However, our analysis needs cannot be case-based. We need to extract these objects into classes to make such analysis more representative. WeSoftwareThe system is not used to solve a problem in a specific event, but to solve a certain type of problem.
In my work experience, object graphs are rarely used in demand analysis. I basically do not use object graphs, but directly use class diagrams. When a few objects need to be used, I even use class diagrams instead, this is nothing wrong and it is easy to understand and solve the problem.

There is a previous exercise that allows you to draw the relationship between you and your other half using the class. In fact, you and your other half are actually very specific people, it should be expressed using an object chart, but I think it is nothing wrong to "confuse" it as a class chart, and it is easier to understand.
As mentioned in the previous section "recursive relationship of classes", "self-contained" and "self-reference" do not mean the object itself, it refers to other instances belonging to the same class.

Here is a brief introduction to object graphs. If you are not very familiar with class graphs, we recommend that you understand the degree of object graphs.

 

3.8 summary and exercises

 

Class DiagramIs the most commonly usedUMLFigure is the best weapon to train your OOA mind. The syntax of a class chart is not very difficult. It is not very difficult to understand the class chart, but it is quite difficult to make good use of the class chart.
At the beginning of this chapter, I specifically brainwashed the developers to correct your understanding of process-oriented and object-oriented. If you are not a developer, this brainwashing will be avoided.
Next, you learned a lot of basic syntaxes for graph classes and made a lot of exercises. Do you still remember the content listed below?

Table 3.1 basic class graph syntax

You have also learned the "recursion" and "Triangle" relationships of class graphs.

Figure 3.40 "recursive" link example

Figure 3.41 "Triangle" link example

In addition to consolidating the knowledge of class diagrams, you can also use examples to analyze the problem ideas and methods.
Basic Steps for graph analysis:
1) Identify the class.
2) identify the main attributes of the class.
3) depicts the relationship between classes.
4) analyze, abstract, and organize various types of data.

After the class is instantiated, it is an object. The graph that expresses the relationship between these objects and objects is an object graph.Requirement AnalysisObject graphs are rarely needed.
Think more, practice more, discuss more, and summarize more, and constantly train and improve your object-oriented analysis capabilities!

Exercise

1. A car has four wheels. Please use a class chart.
2. A freight car also has four wheels, but the front and rear wheels of the freight car are not the same. How do I use a class picture to express it?
3. Use a class chart to represent the composition of the project team. Tip: Think about the roles in the project team? Is the project team architecture tree or network architecture?
4. If you want to design a forum, use a class chart to show the relationship among common Forum elements such as partition, forum, subforum, and post.
5. Select a project you have worked on or are working on and use a class diagram to analyze the project's needs or some requirements.

 

Author: Zhang chuanbo
Www.umlonline.org

 

--- The full text ends here ---

 

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.