Western Lunge (15): Reconstruction to Mode

xiaoxiao2021-03-20  206

Today's question is a bit mean: we have parking, and parking younger brothers. A parking younger brother wants to manage multiple parking lots, and then helps the car to be in the parking lot of the car. Then the boss said, there must be a different strategy to choose a parking lot: Sometimes you have to choose the most space, sometimes you have to choose the least car, the big boss's car should stop, the familiar car must stop cheapest……

The first impression of familiar with object-oriented programmers will think of the Strategy mode. But I am not, because it is not familiar with the object-oriented programmer, the familiar function should be more ... (cold). The first impression thinks, the parking younger brother knows multiple parking lots, actually a list; given a condition to pick up a thing from the list, actually is Accumulate. So, the first thing that thought is to implement an Accumulator first, then use a binary functionor to take Accumulate, and go out. Strategy is the second thought ...

The problem is that this is just a feeling, but the light passage is not enough. It feels likely to be wrong, and it is possible YAGNI (I have Overkill in front of it). And just like Jane, we are consultant, you have to give knowledge Share to others. The Strategy mode is also over, if it is a step, it is an Accumulate. It is estimated that most people have a haraast. This is not a dramatic, and I wrote a Map and Filter in the project. Even Andy almost oska, afterwards Is "Clever Code", Clever is not a good word. Fancy Design is not a problem, but there is reason, but also makes customers understand this reason. Otherwise, the customer has to say that our TWER is holding their money to play coding games.

So today is very serious about the pace of the teacher ... honestly not very serious, but roughly is almost almost. So I heard the Bad Smell once. First, Logic Switch, grab it, separate the changes and unchanged, extract it, get the Strategy mode; then the operation of the traversal list, seize it, the changed portion is "comparison between two parking lots "So use iComparer to implement a comparison algorithm, using the sort () method provided by ArrayList, taking out the first element is OK. Sure enough, although the original idea is approximately bad, it is Overkill: Under this requirement, Binary functor can use iComparer to express, Accumulate doesn't have to write it yourself.

Reconstruction has not finished, and tomorrow will first get the last part of the above, then delete Strategy, get the code that meets my first aesthetic impression and clearer and simple. Today is probably the second day since TWU ... The most learned is the business process modeling and Story, the language is ignorant.

Today, another discovery is prefactoring: This is a good book. Still in today's class, if there is no guidance of the teacher, then you will be guided by the first aesthetic impression. Of course, SMELL is also boot, but Big Picture is equally important. And just like Refactoring, Big Picture is also training. Just now a good time, I have no time to look at this "foundation" book for a long time, I really enjoy it.

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

New Post(0)