Design principles Begins

Source: Internet
Author: User

Uncle Bob mentions seven symptoms of poor design in his book, Agile Software Development-Principles model and practice:

1, rigidity: Refers to the design is difficult to change;

2, vulnerability: Design is easy to be destroyed;

3, Stubborn: design is difficult to reuse;

4, viscosity: Difficult to do the right thing;

5, unnecessary repeatability: excessive design;

6, unnecessary duplication: misuse of the mouse to copy the paste

7. Obscurity: The expression of confusion


The "Stink" of design is mainly because they violate one or more of the design principles, which include:

1. Single Duty principle (the responsibility principle, SRP);

2, open-closed principle (the Open-close PRINCIPLE,OCP);

3, Liskov replacement principle (the Liskov substitution principle, LSP);

4, dependence inversion principle (the dependency-inversion principle,dip );

5. Interface isolation principle (the interface segregation principle, ISP)


So, what is agile design?

Agile design is a process, not an event. It is a continuous process of applying principles, patterns, and practices to improve the structure and readability of software. It is dedicated to keeping the system design as simple, clean and expressive as possible at all times.


Here is a copy of the case in the book to illustrate the difference between poor design and agile design:

Scene: A radio app, the original design boss only need to put music on the good, this demand is very simple, the first version of the design is as follows:

<?php class Radio{public function broadcast () {$music = new music (); $this->play ($music);} Public function Play ($music) {$music->sing ();}}
Well, it looks pretty good, and you're going to get a raise for this great programming skill. Marry mating embark on the pinnacle of life!!!


Unfortunately, very not Xin, demand changes, fried chicken want to chop dead product manager has wood!!!

Now the radio not only to broadcast music, but also to broadcast audio novels, How to do? Of course it's hard not to fall in the smart of you, after all, you have to embark on the pinnacle of life!

Soon, you'll be making the second version of the design:

<?php class Radio{public Static $READBOOKS = False;public function Broadcast () {if (self:: $READBOOKS) {$book = new book () ; $this->play ($book);} else{$music = new Music (); $this->play ($music);}} Public function Play ($stuffToPlay) {if (self:: $READBOOKS) {$stuffToPlay->read ();} else{$stuffToPlay->sing ();}}}
God, you must be a genius, this design on the Earth except your brain, there must be no second brain can be desired!!! , Ah, finally finished the class, go back to see a piece of sleep it!

No, there is a new demand, now the radio also to broadcast talk show, you now how to think sharpening to PM also not, or the activity under the neck began to force code bar!

Soon, the third version of the Code was released:

<?php class Radio{public Static $READBOOKS = false;public static $TALKSHOW = False;public function Broadcast () {if (self: : $READBOOKS) {$book = new book (); $this->play ($book);} ElseIf (self:: $TALKSHOW) {$talkShow = new talkshow (); $this->play ($talkShow);} else{$music = new Music (); $this->play ($music);}} Public function Play ($stuffToPlay) {if (self:: $READBOOKS) {$stuffToPlay->read ();} ElseIf (self:: $TALKSHOW) {$talkShow->talk ();} else{$stuffToPlay->sing ();}}}

Evaluation: The first version of the design is not a problem, but as the demand changes, the bad taste of the code appears, to broadcast more content, the need to set the identifier will be more and more, if/else nesting will become more and more complex, if one day to increase the midnight plate (you understand), we still have to continue to design it?


The Agile Design version:

What is changing in this case is the content to be played, and we can abstract this part into a interface:

<?php Interface () {public function play ();
Specific implementation classes:

<?php class Books implements Sound{public function play () {$this->read ();}}


<?php class Talkshow implements Sound{public function play () {$this->talk ();}}

<?php class Music implements Sound{public function play () {$this->sing ();}}


Radio class:

<?php class Radio{public function play (sound $sound) {$sound->play ();}}

Such a design, the future changes in demand, we just need to add a new implementation class on the line, which also conforms to the design principle of the open and close principle (closed to the modification, opening to the extension).


Of course, agile design does not favor over-design, if there is no late changes in these requirements, the first version of the design is sufficient, there is no need to design for the design, add unnecessary complexity.






Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Design principles begins

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.