[Forum topic] oo questions !!!!!!!

Source: Internet
Author: User

[Question :]

I have read some oo books, but I still don't quite understand them. Hope you can give me some advice.
For example:
The score of a student. If Oo is used for analysis, there should be two objects: Students and scores.
Instructors can modify scores. Who should be responsible for this change? students, teachers, or scores.
Instructor. Modify (), student. Modify (), score. Modify ()

 

[Reply] (part, till now)

Reply:V0v ()() Credit: 100

Object creation is not unique. It depends on the actual situation and application.
In your system, students have very few attributes and behaviors (you can understand what is created to modify the score), and there is no possibility of further expansion, therefore, using scores as an attribute of students and modifying them by students is also an efficient solution. However, in the real system, a student may have scores of many subjects and different periods, at the same time, the role of the students is also very rich, in addition to the examination, there may be many other behaviors and attributes, then at this time, to avoid confusion in the model, you should create the score object to manage your own behavior. At this time, students can aggregate a score.

Reply: W_rose (w_rose)() Credit: 94

The score has been modified, but you do not know which instructor modified the score. This is not allowed.
It is incredible that the instructor has modified the score but cannot find out which score has been modified.

In fact, modification is performed across two objects. It does not matter in which class it is implemented. It only writes one parameter less, but the essence is the same. In the operation, this object is also a default parameter.

Reply:W_rose (w_rose)() Credit: 94

OO requires that the operation modules be packaged according to the type. The OOP programming style is not perfect. If we write down a bunch of operations, and then when it involves multiple objects as parameters, the system will automatically copy one copy in each type module and it seems more intelligent to keep them synchronized.

Reply:Jeffyan77 (jeffyan77)() Credit: 105

There are two principles to consider.

First, D. I. M. (do it myself), that is, the object you are talking about, manage yourself. Data and the Program for data modification must be encapsulated to form an object.

Second, the design granularity (granularity ). Whether a score is an independent object or an attribute of a student depends on how important the score is in your system.

If your system is about Score Management, scores should be an important independent object. At this time, the score should provide a modification method modify (). All modifications must be done through this method, which reflects dim.

However, if your system score is not so important, the score is an attribute of the student, represented by a common data type (such as double), in order to reflect dim, students must provide a way to modify their scores. In fact, when using the double type, you must call the double type method to modify its value. +-The operation is actually the double method. Therefore, the dim of the score (double) is reflected by the OO language.

The instructor modifies the score, which is part of the business logic. To reflect this business logic, the score object's modify () method should have the instructor object parameter, indicating who approved the modification. The instructor object can also have a modifyscore () method. By calling this method, the instructor can modify a score. However, this method is only a call transfer. The real modification must be performed by the score object (if there is no specific score object, it is the student object.

In any case, the instructor should not be the final object for directly modifying the score. Otherwise, you will regard the score as the meat on the chopping board, passively cut by the teacher, or design a program object for it to modify another object, that is, the data object. In essence, the program and data are separated, and the object is canceled.
Reply:Jeffyan77 (jeffyan77)() Credit: 105

In some special cases, separating operations and data is a great way to do this, for example, the visitor mode.

This is like playing Go. The experts have considered a certain level. It looks like a cool-man, but it is a cool-man. Low-handed users do not have to consider any level. Vulgar users are vulgar users. Now you don't have to consider the visitor mode.

Reply:W_rose (w_rose)() Credit: 94

Generally, we first design interfaces in classes that involve underlying operations, that is, scores. modify (Instructor), and then add the corresponding interface to the peer (I .e., the instructor) as needed: instructor. modify the score to make it easy to use. For example, Microsoft's programming framework system is usually friendly to the programmer's interface and easy to use.

Reply:Adsl314 (dd)() Credit: 100

Thank you for your enthusiastic help.
---------------
After reading the replies from so many people, I understand a lot. Let's talk about my thoughts:
First, as yujia120 (Yu Jia) said:
It cannot be simply understood as: score change yourself
Who is the object for data operations?
This understanding will not be confused, and there will be no misunderstandings like active and passive.
Because you cannot identify active or passive behaviors.
We should regard the object as the operator of data.
That is, the d. I .m.
As for who (teacher) sends the request information. This shows who can do what in the business logic. That is, what kind of behavior this object (teacher) has.
--------
Correct the error...

Reply:W_rose (w_rose)() Credit: 94

"Responsibilities" have many meanings. In the computer field, record is responsible for dealing with permanent storage systems. In the "business field", this operation is neither a record nor a teacher, but also a targetrecord, that is to say, only when three parameters are together can this operation be understood.

Reply:W_rose (w_rose)() Credit: 94

Let's take a look at the definition in the above record class. Combined with the business definition, the programmer may argue that the record lost the teacher before it was saved!

Therefore, in the face of other programmers as users of these two types, development should only start from "adaptation and nature. At this time, the debate can be divided into two layers: "business design" and "storage design.

Reply:Ozzzzzz (agile)() Credit: 161

In fact, the above discussions have almost no value at all, because these discussions basically do not take into account what the situation is in the actual project. They are simply thinking, thinking, and theory. Let's take a look at the actual situation in the project.
First, we must understand that the analysis model is not the same as the design model. Now we are talking about the design model.
In fact, the score is definitely not a pure score, but a comprehensive evaluation of a student, including scores, subjective judgment, length of practice and other factors. The modification of the score is almost doomed to happen in a certain stage. At the same time, the determination of a score can also be considered as a special modification. At the same time, there are a lot of business logic to modify and identify the score, such as the calculation of the score (you can understand the complexity of the process of determining the score of GRE and other foreign exams ), conversion of test scores and final scores (the calculation method of the test scores in the term and the calculation method of the final score in the term ). The logic of modification is also very complex. For example, the modification of the current score may be different from the academic year score. The Business Process for modifying the score may also have different practices in different subjects; the records made during score modification may vary in different environments. These logics may change frequently, and even if they do not change their complexity, they cannot be simply solved by a simple method.
The so-called instructor-Modify () or score-Modify () is almost impossible and absurd.

Reply:Ozzzzzz (agile)() Credit: 161

Darren_zhu_nz (. NET-_-is also used in rural areas -_-)
"It is necessary to simulate an actual situation"
Who do you think can simulate the actual situation before I speak? In the final analysis, any method you discuss is ridiculous in practice and is useless. In actual implementation, there is no reference value. this so-called idea is naive, ridiculous, and meaningless.
This gives me a worry. to illustrate a problem, we always give examples that are not typical, simple examples, and the problems we want to explain. this gives a misunderstanding to those who learn these methods. They think that the world seems to be so typical. This is just so simple, ignoring the actual complexity of the world.
I don't think anyone has no practical experience in this scenario, but everyone ignores the complexity of the world.
Instructor. Modify ()
In fact, you ignored 1. not every teacher has the right to modify. 2. Not every teacher has the right to modify every score. 3. Not every change is made by the teacher, there will be scenarios where the scoring standard changes (for example, the original score is 140 points, and now the current score is 100 points; the original score is not weighted, and the current score is weighted; the original score does not take into account the time of the training, but now the time of the training should be considered)
Your use of score. Modification () also has many defects. You can imagine all the defects on your own.

In fact, there is a general situation in which the actual ideas are always simplified and complicated in practice. The discussion here is a typical simplification.

Reply:W_rose (w_rose)() Credit: 94

Nothing can be referred to as "simple.

As a matter of fact, you can put a monkey in front of the keyboard for a long time. It will write all the posts on this forum to you, without the hard work of us!

That is to say, if anything can be taken into consideration, it can be demanded in the guise of "perfect and advanced. The most difficult thing to do is to be realistic, be right, and not do things that are not your responsibility (Object design ).

The so-called "Modify permission", if you want to design it for the first time, then you do as required. If you want it to be an extension of basic functions, you can do it in the inherited sub-objects, which is also part of the "do it self" mentioned above.

Reply:Ozzzzzz (agile)() Credit: 161

I will explain this question a few more times.
In fact, both of them are acceptable. As long as you are in a simple hypothetical environment, there is no right or wrong problem, and the difference between good and bad is also very small, this old saying has already been explained. The key is that when you put these things in a specific environment, you will find them both awkward and difficult to grasp.
If you only want to complete a job, you can use this question. However, software engineering does not serve academic research, but our specific work. When you do your homework, you should ask your teacher. His answers will help you get high scores. There should be no need to replace these teachers here.
For example, if you say that a student cannot change his or her score, but in fact many scores can be made based on the score modified by the student. For example, if he thinks that the teacher has not considered his own problem completely, the modification he requested at this time is different from the business meaning of the change he initiated by the teacher, this kind of modification based on student requirements is something you need to consider in almost all environments. For example, the number of scores is not modified by students or teachers. For example, the school increases the number of scores to encourage social practice. This kind of thing often happens in the school. I don't believe any student doesn't know. It's just whether you have considered the problem based on the actual situation, not just the question.

 

[Original post ]:

Http://community.csdn.net/Expert/topic/3285/3285957.xml

 

 

 

 

 

 

 

 

 

 

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.