23
1 Design Lecture 4 – Practical Issues in Design CIS 6101 – Software Processes and Metrics

1 Design Lecture 4 – Practical Issues in Design CIS 6101 – Software Processes and Metrics

Embed Size (px)

Citation preview

Page 1: 1 Design Lecture 4 – Practical Issues in Design CIS 6101 – Software Processes and Metrics

11

Design

Lecture 4 – Practical Issues in Design

CIS 6101 – Software Processes and Metrics

Page 2: 1 Design Lecture 4 – Practical Issues in Design CIS 6101 – Software Processes and Metrics

2

IntroductionIntroduction

►Design is very important.Design is very important.►Well designed software is Well designed software is

apparent to the users and programmers alikeapparent to the users and programmers alike►Users: usability; learnability; architectueUsers: usability; learnability; architectue

Is useful, easy to use, maintain, extend, and Is useful, easy to use, maintain, extend, and understand.understand.

► In order to establish sustainable software, In order to establish sustainable software, software must be software must be designed to support designed to support and enhance changeability.and enhance changeability.

►Agility is possible Agility is possible onlyonly with the ability to with the ability to modifymodify and easily and easily extendextend the software. the software.

Page 3: 1 Design Lecture 4 – Practical Issues in Design CIS 6101 – Software Processes and Metrics

3

Introduction – (2 of 2)Introduction – (2 of 2)

► Design clearly has a Design clearly has a central / essentialcentral / essential role role in software development regardless of in software development regardless of methodology. methodology.

► Design: Design: most difficult component of SE most difficult component of SE due to factors such as due to factors such as schedule, schedule, people on the project and people on the project and constant change. constant change.

► Designs cross a spectrum of being Designs cross a spectrum of being overdesignedoverdesigned and and under-designedunder-designed with an with an unfortunate number of projects at either end.unfortunate number of projects at either end.

Page 4: 1 Design Lecture 4 – Practical Issues in Design CIS 6101 – Software Processes and Metrics

4

Over-designedOver-designed Projects Projects► May be the result of over-zealous application of May be the result of over-zealous application of

engineering approach to software development. engineering approach to software development.

► This is the most widely taught approach to software This is the most widely taught approach to software development, which is development, which is toptop downdown..

► Top Down advocates Top Down advocates thoroughthorough design before testing; design before testing; assumes assumes thoroughthorough understandingunderstanding of the of the requirements.requirements.

► Unfortunately, when TDD is applied to software, result Unfortunately, when TDD is applied to software, result isis often overdesign and often overdesign and high cost of change.. high cost of change..

► Also, this approach is usually accompanied with stacks Also, this approach is usually accompanied with stacks of documents and no code to support the elaborate of documents and no code to support the elaborate design! design!

Page 5: 1 Design Lecture 4 – Practical Issues in Design CIS 6101 – Software Processes and Metrics

5

Under-designedUnder-designed Projects Projects

►aka “code-then-fix” development. aka “code-then-fix” development. Also called ‘fly by the seat of your Also called ‘fly by the seat of your pants.’ Just as bad.pants.’ Just as bad.

►Here, there’s little or no design.Here, there’s little or no design.►Change is VERY difficult due to Change is VERY difficult due to

tangled mess of code or tangled mess of code or hard to comprehend.hard to comprehend.

►Painful to work with, but may be a Painful to work with, but may be a great form of job security. great form of job security. <Discuss><Discuss>

Page 6: 1 Design Lecture 4 – Practical Issues in Design CIS 6101 – Software Processes and Metrics

6

The Middle GroundThe Middle Ground

►For sustainable development, we need For sustainable development, we need a middle ground.a middle ground.

►Capture the good points of Capture the good points of bothboth over-zealous design and over-zealous design and woefully inadequate design. woefully inadequate design.

►The rub: Need to have the The rub: Need to have the disciplinediscipline and and abilityability to think about to think about goodgood designdesign while proceeding as while proceeding as rapidlyrapidly asas possiblepossible. .

Page 7: 1 Design Lecture 4 – Practical Issues in Design CIS 6101 – Software Processes and Metrics

7

Extreme Programming (XP) Extreme Programming (XP) (Beck 2004)(Beck 2004)

► Outlines Outlines evolutionaryevolutionary or or emergentemergent design.design.► Method relies on Method relies on simplesimple designdesign – –

Design what you need, Design what you need, Refactor (disciplined code changes) and Refactor (disciplined code changes) and Test-first development (to ensure the behavior stays as Test-first development (to ensure the behavior stays as

originally intended. originally intended.

► Idea: get software into hands of users asap;Idea: get software into hands of users asap;► Evolve the design as requirements change.Evolve the design as requirements change.

► Opponents cite that Opponents cite that evolutionaryevolutionary designdesign can lead can lead to unintended to unintended oscillationoscillation, where the same code is , where the same code is repeatedly changed due to insufficient thought not repeatedly changed due to insufficient thought not put into the design. (There are many other issues put into the design. (There are many other issues too – Later)too – Later)

Page 8: 1 Design Lecture 4 – Practical Issues in Design CIS 6101 – Software Processes and Metrics

8

Sustainable DevelopmentSustainable Development

►Need Need balancebalance the good aspects of the good aspects of front-end front-end designdesign w/various design techniques w/various design techniques w/w/evolutionaryevolutionary designdesign while avoiding the while avoiding the pitfalls of each.pitfalls of each.

Avoid overdesigningAvoid overdesigning a solution by erring on the a solution by erring on the side of side of simple designsimple design while avoiding the while avoiding the documentation trapdocumentation trap by focusing on by focusing on producing producing software not documentssoftware not documents..

AvoidAvoid under-designing and code oscillationunder-designing and code oscillation by by thinking ahead and having a thinking ahead and having a design vision and design vision and guiding principles.guiding principles.

Page 9: 1 Design Lecture 4 – Practical Issues in Design CIS 6101 – Software Processes and Metrics

9

How to Merge Good Up-Front How to Merge Good Up-Front Design w/Good Evolutionary Design w/Good Evolutionary

DesignDesignOne way: is a One way: is a throughthrough understandingunderstanding of good, up- of good, up-

front design and good evolutionary design.front design and good evolutionary design.

► Practitioners of up-front designPractitioners of up-front design concentrate on understanding what makes a good designconcentrate on understanding what makes a good design

► Practitioners of evolutionary design Practitioners of evolutionary design focus on understanding good designs resulting from focus on understanding good designs resulting from

evolution and how they evolved. evolution and how they evolved.

► Understanding the Understanding the evolutionevolution of great software of great software designs is designs is more usefulmore useful than studying the great than studying the great designs themselvesdesigns themselves. .

► It is in the evolution that the real wisdom lies. It is in the evolution that the real wisdom lies. ► Without knowing Without knowing howhow the design the design evolvedevolved into a into a

design, you are more likely to misapply and over-design, you are more likely to misapply and over-engineer them.engineer them.

Page 10: 1 Design Lecture 4 – Practical Issues in Design CIS 6101 – Software Processes and Metrics

10

But to But to UnderstandUnderstand Good Good Design Evolution: Design Evolution:

►One must be able to recognize good design.One must be able to recognize good design.►Design is Design is pointlesspointless without evolution, without evolution,

because evolution is inevitable.because evolution is inevitable.

► Lastly, good design doesn’t just emerge from Lastly, good design doesn’t just emerge from a single individual no matter how brilliant. a single individual no matter how brilliant.

►Good design requires collaboration, because Good design requires collaboration, because collaboration provides support as the team collaboration provides support as the team collectively works toward their goal while collectively works toward their goal while balancing good designbalancing good design and and good design evolution. good design evolution.

Page 11: 1 Design Lecture 4 – Practical Issues in Design CIS 6101 – Software Processes and Metrics

11

Different Kinds of DesignDifferent Kinds of Design► In typical software projects there are many In typical software projects there are many

different kinds of design.different kinds of design. Software architecture (classes, hierarchies, Software architecture (classes, hierarchies,

methods)methods) The user interface (UI)The user interface (UI) The web site The web site Marketing and sales material, (yes! Must be Marketing and sales material, (yes! Must be

designed!)designed!) User documentation (yes, documentation must User documentation (yes, documentation must

be designed), be designed), Test infrastructure, andTest infrastructure, and Database structureDatabase structure

►Despite their differences, there are common Despite their differences, there are common design practices that can be applied.design practices that can be applied.

►We will discuss them.We will discuss them.

Page 12: 1 Design Lecture 4 – Practical Issues in Design CIS 6101 – Software Processes and Metrics

12

Practice 1: Design Vision – Practice 1: Design Vision – simply an architectural overviewsimply an architectural overview► Iterative Design is difficult if you do not have a vision Iterative Design is difficult if you do not have a vision

for the project even if you are only adding to an for the project even if you are only adding to an existing base.existing base.

► A design vision / conceptual design is an A design vision / conceptual design is an overall overall picturepicture of the of the piecespieces of your software of your software What they are, What they are, what each does, what each does, how they interoperate to solve problem at hand.how they interoperate to solve problem at hand. How they are dependent or provide for other components, How they are dependent or provide for other components,

etc…etc…

► Design vision can be as simple as a hand-drawn Design vision can be as simple as a hand-drawn annotated sketch on a whiteboard or a UML diagram. annotated sketch on a whiteboard or a UML diagram.

► Regardless of form of vision, it should be Regardless of form of vision, it should be kept up to kept up to date and must exist.date and must exist.

Page 13: 1 Design Lecture 4 – Practical Issues in Design CIS 6101 – Software Processes and Metrics

13

Practice 2: Guiding PrinciplesPractice 2: Guiding Principles

►This too can be simply a This too can be simply a short list of short list of statements specifying overall statements specifying overall design goals / requirements.design goals / requirements.

►Helps designers make Helps designers make decisions decisions consistent with design intent. consistent with design intent.

►However, where the vision describes However, where the vision describes whatwhat the project is about, the guiding the project is about, the guiding principles describe principles describe howhow the project the project should be built. should be built.

Page 14: 1 Design Lecture 4 – Practical Issues in Design CIS 6101 – Software Processes and Metrics

14

Two Distinct Principles Two Distinct Principles Recommended:Recommended:

►Engineering Guiding PrinciplesEngineering Guiding Principles – – describe describe howhow the project is implemented the project is implemented in technical terms that the project in technical terms that the project team’s developers can understand.team’s developers can understand.

►User Experience Guiding PrinciplesUser Experience Guiding Principles – – describe describe attributes the user cares about.attributes the user cares about. Described in a Described in a user-centric wayuser-centric way that that

everyone on the team can everyone on the team can understand. understand.

Page 15: 1 Design Lecture 4 – Practical Issues in Design CIS 6101 – Software Processes and Metrics

15

Practice 3: Simple Design (1 of Practice 3: Simple Design (1 of 2)2)

►Means only design and code Means only design and code what you what you know know you need you need while always striving for while always striving for simplicity. simplicity. Extreme Programming – (recall) states Extreme Programming – (recall) states only only

design what you need immediatelydesign what you need immediately. Recall . Recall also that this can lead to oscillation, where a also that this can lead to oscillation, where a body of code is continually re-factored to meet body of code is continually re-factored to meet the current requirements, because there was no the current requirements, because there was no design or planning ahead.design or planning ahead.

► If you If you knowknow something is going to be something is going to be required, then required, then designdesign it and it and buildbuild it, it, even even ifif this means the user may only see a this means the user may only see a limited immediate benefit. But keep design limited immediate benefit. But keep design simple.simple.

Page 16: 1 Design Lecture 4 – Practical Issues in Design CIS 6101 – Software Processes and Metrics

16

Practice 3: Simple Design (2 of Practice 3: Simple Design (2 of 2)2)

►InterfacesInterfaces: Add interfaces later that : Add interfaces later that you don’t you don’t immediatelyimmediately need; need;

►DesignDesign PatternsPatterns: If problem is : If problem is understood well enough to know its understood well enough to know its solution can be found in a solution can be found in a designdesign patternpattern, then pattern should be used., then pattern should be used. Patterns work and are well-understood.Patterns work and are well-understood. But patterns aren’t perfect and again, you But patterns aren’t perfect and again, you

need to always think about simplicity first.need to always think about simplicity first.

Page 17: 1 Design Lecture 4 – Practical Issues in Design CIS 6101 – Software Processes and Metrics

17

Some are Uncomfortable with Some are Uncomfortable with this Approach…this Approach…

► Important to accept that you’re going to get it wrong Important to accept that you’re going to get it wrong sometimes and over- or under-design in some sometimes and over- or under-design in some instances.instances.

► That’s software development!!That’s software development!!

► FixFix problem problem asapasap, , learnlearn from from experienceexperience, and , and movemove onon..

► Teamwork, knowledge, experience, and Teamwork, knowledge, experience, and collaboration are vital to make the right decision.collaboration are vital to make the right decision.

► People learn from each otherPeople learn from each other and and the greater the the greater the collective experience and knowledge from the collective experience and knowledge from the team, the greater the chance that the correct team, the greater the chance that the correct decision are going to be reached. decision are going to be reached.

Page 18: 1 Design Lecture 4 – Practical Issues in Design CIS 6101 – Software Processes and Metrics

18

Practice 4: Refactoring Practice 4: Refactoring (1 of (1 of 6)6)

► Refactoring is the process of Refactoring is the process of changingchanging a a software system in such a way that it does software system in such a way that it does not alter the external behavior of the code not alter the external behavior of the code yet improves its internal structure.yet improves its internal structure.

► ► It is a It is a disciplineddisciplined wayway to clean up code tht to clean up code tht

minimizes the chances of introducing bugs.minimizes the chances of introducing bugs. It is NOT simply reviewing to improve code.It is NOT simply reviewing to improve code. Considerable discipline and precision are Considerable discipline and precision are

needed!needed!

► In essence, when you re-factor you are In essence, when you re-factor you are improving the design of the code after it has improving the design of the code after it has been written (Fowler, 1999)been written (Fowler, 1999)

Page 19: 1 Design Lecture 4 – Practical Issues in Design CIS 6101 – Software Processes and Metrics

19

Practice 4: Refactoring Practice 4: Refactoring (2 of (2 of 6)6)

► Refactoring involves changing code in a Refactoring involves changing code in a very very disciplineddisciplined wayway so that the so that the structurestructure of the code is changed of the code is changed but the code’s but the code’s behaviorbehavior remains unchanged. remains unchanged.

► It involves a step-by-step approach with It involves a step-by-step approach with tests tests inin placeplace to catch problems as you to catch problems as you proceed.proceed.

►RewritingRewriting is performed in a more ad-hoc is performed in a more ad-hoc delete/replace manner.delete/replace manner.

►RefactoringRefactoring will help keep your code will help keep your code clean, rewriting may not. clean, rewriting may not.

Page 20: 1 Design Lecture 4 – Practical Issues in Design CIS 6101 – Software Processes and Metrics

20

Practice 4: Refactoring Practice 4: Refactoring (3 of (3 of 6)6)

► It is simply It is simply notnot rewriting. rewriting. ► It is It is notnot a general cleaning up of code. a general cleaning up of code.

► Refactoring uses Refactoring uses terminologyterminology and and patternspatterns such as Extract Method, Extract such as Extract Method, Extract Super-class, etc.Super-class, etc.

► Refactoring requires Refactoring requires automatedautomated teststests..► Again, Refactoring is Again, Refactoring is notnot synonymous with synonymous with

rewriting!!rewriting!!

Page 21: 1 Design Lecture 4 – Practical Issues in Design CIS 6101 – Software Processes and Metrics

21

Practice 4: Refactoring Practice 4: Refactoring (4 of (4 of 6)6)

►RefactoringRefactoring creates an image of the change creates an image of the change that can be observed in looking at the re-that can be observed in looking at the re-factored code.factored code.

►RewritingRewriting does not guarantee better code or does not guarantee better code or code easier to understandcode easier to understand

►Refactoring should lead to better design Refactoring should lead to better design because of the steps involved with because of the steps involved with automated tests in place catch problems as automated tests in place catch problems as the refactoring proceeds and ensure that the refactoring proceeds and ensure that the behavior of the resulting changes is the behavior of the resulting changes is correct. correct.

Page 22: 1 Design Lecture 4 – Practical Issues in Design CIS 6101 – Software Processes and Metrics

22

Practice 4: Refactoring Practice 4: Refactoring (5 of (5 of 6)6)

► The quality of communication is high with The quality of communication is high with refactoring (vice rewriting)refactoring (vice rewriting) Has its own language usedHas its own language used ““In this change I did an ‘Extract Method’ refactoring, In this change I did an ‘Extract Method’ refactoring,

removing largely duplicated code from methods X, Y, removing largely duplicated code from methods X, Y, and Z”and Z”

► The type of refactoring (extract method) The type of refactoring (extract method) immediately conveys to another developer an immediately conveys to another developer an immediate and rough feeling of the changes that immediate and rough feeling of the changes that were made and the complexity of the work were made and the complexity of the work required without having to look at the code. required without having to look at the code.

► The The level of confidencelevel of confidence is higher with is higher with refactoring than with rewriting. refactoring than with rewriting.

► This is due to the This is due to the disciplinediscipline required. required.

Page 23: 1 Design Lecture 4 – Practical Issues in Design CIS 6101 – Software Processes and Metrics

23

Practice 4: Refactoring Practice 4: Refactoring (6 of (6 of 6)6)

►With refactoring, do not make multiple With refactoring, do not make multiple changes at one time.changes at one time.

►Make small changesMake small changes; ; safe stepssafe steps that can be that can be verified through testsverified through tests. .

►However, when writing code, it is too However, when writing code, it is too easy to approach a problem with wild easy to approach a problem with wild abandon, which often results in a abandon, which often results in a worse state or no improvement. worse state or no improvement.