Keep it simple and stupid is the kiss Principle. simplicity is the beauty of software design. simple design makes software products easy to develop and maintain. simplicity represents high quality, less overtime, and everyone wants their work to be simple.
In addition to the KISS Principle, there should be a more important principle: useful. meeting requirements is a low limit for all products. maybe the demand itself should also be kiss. A simple requirement means bottom cost and high efficiency. unfortunately, it is sometimes difficult for customers to restrain their desires. maybe the kiss we see from the customer's perspective is not exactly a concept in our developers' eyes. some people say that good design is made by the customer. Developers are only helping the customer design.
KeepIt simple and stupid, the most difficult thing is keep. it is not difficult for a person to make a simple design. What is difficult is to keep the design simple in the Process of demand changes. keep is the key, and the time of keep is the life of this design. when a product can no longer keep simple, maintenance becomes more and more difficult. Gradually, it cannot add any changes, and his life will soon end. upgrade means a new one.
Keep simple is to resist changes in demand. The initial requirement is always relatively simple, for example: design a car to driveProgramHe will stop at the red light and move forward at the green light.
Solution 1:
If Red_light Then
Stop ()
Else If Green_light Then
Go ()
End If
This is a simple requirement, and the solution is simple. but if a person in front of a car is crossing the road, he is walking slowly. at this time, of course, go is not allowed. You should press the horn and wait for him to go. solution 1 must be modified:
If Red_light Then
Stop ()
Else If Green_light Then
If People_ahead Then
Ring ()
Else
Go ()
End If
End If
The actual situation may still change. For example, an ambulance is driving at a horizontal intersection despite the green light, or there is a road sign in front of "Please bypass road repair "...... in various cases, the result is to add a new judgment in the original if-Else.
This is a simple design, but it is difficult to keep simple.CodeWhen the number of parts is constantly increasing and the length exceeds 500 lines, any change in related requirements is a nightmare. I think everyone has encountered more complicated cases in software development.
Solution 2:
Imagine a thing called strategy. It has the following features: it has a name and a priority. He can determine a situation and return the actions that should be taken in this situation. the red light stops and the green light goes on. If someone honks the horn at the front, it is a specific strategy. is the following structure:
There should also be an action, which represents the action that should be taken after the policy judgment. Forward, stop, and honking are all specific actions. This structure:
The final program running process is as follows: first initialize a stratage list and put all the policies to be judged in it. determine these policies one by one as needed, and then execute the actions returned by the highest priority policy.
Dim Action As New Action
For Each Stratage In Stratage_list
If Stratage. Priority < Action. stratage. Priority Then
' If the priority of the current policy is smaller than the priority of the behavior Policy, you do not need to judge this policy.
Continue
End If
Stratage. Judge (action, ENV)
Next
Action. Do ()
With such a design, policies become increasingly complex as demand changes. You only need to add a new stratage, assign a proper priority, and then derive a new action based on the situation. the complexity of the program will not increase.
Quick & dirty vs over-design
The design should start with simplicity and keep it simple. make a simple design. When the demand changes, the first thing we should do is rebuild the design to make it simple again, and then add new functions. simple is not quick and dirty. simple things may become complicated. Complicated things may be more simple in nature. this requires a full understanding of the needs, and of course there is a little bit of skill. excessive design is also a problem, but considering the pain of maintenance personnel, an over-designed system is usually easier to maintain than a quick and dirty system.