Use OO Design Chat Room

zhaozj2021-02-16  65

OO is a very familiar concept for the current programmer, and OO can also bring us a lot of benefits and our procedures, and the reuse of the code saves a lot of development time, and a truly use OO design and encoding. Software will also benefit from OO in the process of upgrading and maintenance.

However, OO may only stay in the stage of superficial understanding of the superficial understanding of the superficial understanding of the developer (especially those using Delphi, etc.), often simply use the class provided by the development tool during the development process. Simplely reused the classes provided by these development tools, which may not take into account the future reuse (except for component development), and rarely consider the use of OO from future upgrade maintenance. Of course, these arguments are only propensions from my personal development process. It is very likely that the purpose of proposing. I have written this article is not to guide the programmer's life. I just hope to let more people from me. What you want and income (although it is possible to be wrong) get some inspiration, avoid walking the same bend as me, of course, do not exclude the reader to read the last found this is a possibility of garbage, for the time caused for these readers A deep apology of the waste of energy.

Here I also take a slight time I have used the two development languages, Java and Delphi (more should be said to be a tool), my program development is starting with Delphi, Delphi is indeed very powerful, for me now. Some are too strong, he almost lets you stop thinking, so that our work is on the drag control. This has indeed improved efficiency, but it also loses something else. It is our own class. In the process of using Delphi, I rarely consider how to develop a class, now I want to develop it at that time is a Interface or functional development, the development documentation is provided by others, it is basically such a kind of idea, there is an interface with a document, which is to describe what functionality implemented in this interface, which does not mention something about the class. And your own development process is also a creation form for a single Unit, basically is basically used to provide shared functions and variables. Of course, there is no difference in development work, but for our own reuse and future maintenance, there is no benefits that OO should get.

Java is different, it does not allow non-class, that is to say, no matter what you think when you write the program, you wrote the class, which makes me think. Of course, at the beginning, almost use the class as a package (package), many classes are a combination of various methods related to a certain function, where is the role from reuse and provincial perspectives. So I want to say here, to be a good programmer, write a good program, think about it, not only to remember a lot of API and find a solution to the problem, we need more Reflections, is currently about OO thinking (it may be other thinking after 20 years), thinking about how to solve the problem through OO, and make it realized from OO. Of course, about Java may not be able to ensure the continuity of this thinking after the fact that most of our development is mainly concentrated in the web end, and the UI contact, and does not know how to start contacting a lot of GUI.

I also said a lot of nonsense, now I now go forward. The chat room believes that people who have seen this article have certain understandings, or many people have developed themselves, and they will basically do this, and some people can talk to another person, post pictures, and some Other features, such as administrators can kick, and so on. I don't have to read the code of the chat room, but I think if we use Java development, we must first have a USER class, and each person chatting in the chat room is an instance of a user. Many people see this may think, what else is there, and give each function to the Class of this Class. Is there anything else? There is no doubt that this can solve the problem, and I believe that most of them can develop such a code, but such a job is undoubtedly a lot of problems, if I want to improve this chat room, such as hit people, In the chat room, two people play each other, according to the above method, I need to add another method to the USER Class, and later upgraded, I can get married in the chat room ..., so this user will change Get bigger and bigger, you can imagine what kind of procedure is. (Of course, it is also possible that this chat room will no longer improve after the first development, because the function is not chatting here, haha, I really don't know whether it is a celebration or it should be done.)

If someone is experiencing such a truth, it may be found that there is a similar speech, kicking, etc., which is similar, that is, in addition to their names, the same return value, the same parameters. In this way, we can put it in a method, judge it in this method, perform different actions, but if these actions are still used as the user's method, it is still not a good solution, we It is still a huge class, then why don't we handle the action as an object? That is to say, we are creating a class name called Action, and USER creates an instance of the corresponding action according to the parameters you receive, and what is the effect of this Action all in the Action itself internal processing. And this time we encounter two solutions, 1, process all Action as a class; 2, different Actions as different classes. I think the future program is a better solution, because if we handle all Actions as a class, we just transfer the part of the User to a class, and with the continuous improvement of the system, This class is still endless growth. This seems to be not a good improvement, of course, there is a case that the Action class does not change in the system upgrade, that is, put all logical records in the database, which increases the logic to increase the record in the database. The Action's code does not change, but how to achieve such programs and database design, I want to be a big challenge to now. Now let's see if we use different Action classes that make these classes have some inconvenience, and we will find that the ways of these classes are the same during the development process, and they are with a TO ( User's instance) Parameter, so we can use this method as an interface DOABLE method, then let us implement this interface, at the same time, in User calls these anctions, we use Doable declare variables, use Each different Action is instantiated. Of course, if you are willing to do more improved, you can write the instantiation of the action into a factory class, which is passed to a parameter of this factory class, and the factory class produces a different implementation of DOABLE Action objects based on this parameter. And User Class does not understand what is the internal activity of the Action object, and he only needs to execute this action. Such a design seems to be more compliant with object-oriented design, let's take a look at this design method for the benefits of future system upgrade, if we need to add a function, we need to add a new class, of course this class is to be implemented DOABLE interface, then if we write a factory class, we need to add the corresponding code in this engineering class to generate this new action according to the appropriate conditions, and the code for other parts can not affect, if We want to do more simplification, we can write logic in the factory class into a configuration file, in this configuration file, we record two parameters one is the parameter passing to the factory class to generate an action method, one is this parameter correspondence The name of the Action class, so we can only modify the configuration file when adding an action, and the factory class code does not need to be changed. (This part seems to be obtained according to Struts' design.

Copyright: IDILENT website reproduced please indicate the author's other reprint, please contact the author (iDilent@yahoo.com.cn).

转载请注明原文地址:https://www.9cbs.com/read-17179.html

New Post(0)