Chatting Domain Logic Patterns-

xiaoxiao2021-03-06  18

Reflections in Domain Logic Patterns recently, this also has to explore the answer from the books of the pylinders. Look at the Patternals of Enterprise Application Architecture of Martin, it feels slightly to understand.

On the issue of Domain Logic Patterns, Martin comes down to three main forms. Transaction Script, Domain Model, Table Module.

The nouns in Java are really a lot, can't make people feel the mind. Simply put, Domain Logic Pattern is about what kind of Domain Model constructs and processes them to complete business logic. I don't intend to repeat Martin's brilliance of this problem. If you can see his book, there are many friends in China, I have already paid attention to this problem, and I can take a look at the blog of transparency. I just want to say this problem in the way. So I wrote the scene of this description below.

The boss made me do a full of robots as an actor. These robots are in their own way, such as where the stage is in the stage, what is the word; not only, these robots can define complex relationships with other robots, such as a robot is their own wife, and a group of robots Is your own child.

================================================ martin: From the OO angle, your drama is It is equivalent to a group of business logics to be completed. These robots are equivalent to Domain Model. The property of the robot is equivalent to the properties of Domain Model. The relationship between the robot and other robots is equivalent to entity's relityship ====================================== ==

The boss also made a message, this drama has a fully automatic video, what is the position of the robot to go, what is the word, saying it. Fortunately, the robot is provided with a DAO interface to save the internal state of the robot, but this DAO interface is not done, we have to follow this interface to achieve the function! According to robot manufacturers, you can use different ways to save robots, such as saving in the file, save it in the database, and so on. The manufacturer said that this interface is not only the robot can call, but also people who control the machine can also call! It is very powerful and transparent! I am ourselves: nonsense, you have nothing to do, you can't finish it. ================================================ martin: Well, the manufacturer's practice is quite good , A interface is provided, which is also convenient for the user's extension, the robot's internal or manipulated people is also transparent. Let's call it DAO layer ========================================

I feel that the most suitable is to use a database to record this information, but the boss only provides me a relational database. I realize that the problem is serious, and the object-style data stored a relational database can be a bit trouble, I still It's more lazy, the work is not worn, and finally let me find a component called Hibernate. This thing is very good, as long as there will be the interface of the DAO.

====================================== Martin: You don't surprise, Dao is also for Hibernate. Just a thin package, if you don't have to consider the expansion, you can do Hibernate directly in the robot, but this is still a bit less elegant. ====================================== In order to let these robots automatically perform drama, there is no script how to ! So I started writing the script for the plot. These robots are still very stupid, from A points to B point this action, I have to explain in the script, I have a point from A to B. I started from A point. Rice-azimuth walks 5 meters - reach the B point. Every time I have to repeat the things above the script, how people are painful! I dream: If I only give the robot from the A-B directive, what good he can go in the past! ! ! In that, I just wrote from A to B as long as I wrote it. That put the function of such a to b, make a script in the robot, I can't do it if the robot is complete? So I found the manufacturer's technical support MM, I tell her about my needs, she said that our company has such a programmable robot, but your company's purchases are uncharacted robots.

OMG! Let me handle me in the script in the script! Will die! I am helpless, but I finished a lengthy script. However, although it is long, it is more simple and intuitive, and I don't have to consider some preset features inside the robot. Anyway, step by step, pressing my script.

======================================= martin: I really understand your pain, actually Your pain is now popular Transaction Script practice, this practice peels with the inherent way to Domian Model, put it in Script. This is what I said to anemia Domain Model, and in your opinion, there is such a wood robot without programming. This is what we have to avoid. ======================================= Due to the performance of the performance, in the second performance At the time, I tried to ask the boss to replace the programmable robot and threaten him, don't let me go. The boss has achieved a lot of success in the previous machineman drama, or satisfied my request, so I would like to order a batch of programmable robots in the robot company MM.

But what is the problem that I should do to these robots? Which features are indeed inherently inherent, which features I need to explain in the script, this problem is really headache.

================================================ martin: This is the difficult point of Domain Model It is not an easy thing to build a beautiful and compact Domain Model. But you still have to be proud of your actions. You are now giving wood people thinking, let him really become a robot, so I still stick to it, although I will find my robotic function, I don't worry, we There is always a way to make this model better, children still go to see this book "domain-driven design" ===================== ================== Because I finally built a very good model, the script is simple and flexible, and once the drama of these robots is needed, some methods inside these robots It is possible to reuse, to do a lot of burden for me to make new scripts, I think it is really very good to use such a robot.

======================================= martin: Child, you finally got the return, actually The Transaction Script mode of your previous use is the process-oriented rather than object-oriented. From the appearance, you do have a lot of model, but these models are just Domain Data Struct, not Domain Object, because according to Object's definition, Object needs There are data and operations. We have been hitting object-oriented concepts for a long time, in Transaction Script. We really have to go back to Domain Model, let us peel out from Service Layer from Service Layer, and press NOT. In fact, there is such a refactor method that allows you to return from Transaction Script to Domain Model. This will look for it yourself. ======================================= Write this article I refer to several documents Patterns of Enterprise Application ArchitectureBy Martin Fowler, David Rice, Matthew Foemmel, Edward Hieatt, Robert Mee, Randy Stafford

AnemicDomainmodelhtp: //martinfowler.com/bliki/anemicDomainmodel.html

Transparent thinking about this discussion about this http://gigix.blogdriver.com/gigix/166013.html

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

New Post(0)