Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed...

51
Best Practices

Transcript of Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed...

Page 1: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

Best Practices

Page 2: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

2

How to design a Software Solution

• The plans or designs: – Represent the agreed upon needs of the user

(“contract”)– Communicate what the programmers need to

implement– Assist future programmers in maintaining or

enhancing code

Page 3: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

3

Design Tools

• Design methods– Describe how to design a solution (specify design

practices and strategies)

• Design patterns– Offer generic solutions to a problem by describing a

problem and a strategy for addressing the problem

• Representation– Assists in modeling the intended system

– Assists in evaluating its behavior

Page 4: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

4

Designs will include descriptions such as:

• The static structure of the system

• The data objects

• The algorithms

• The system packaging

• The component interactions

• The process being designed

Page 5: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

5

Levels of design detail

• Level 1: The software system– High level design of the entire system

• Level 2: Division into subsystem or packages– Business Rules, User Interface, Database Access,

System Dependencies

• Level 3: Division into classes within packages• Level 4: Division into data and routines within

classes• Level 5: Internal routine design

Page 6: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

6

Elements of good system architectures

• Program organization• Major classes• Data design• Business rules• User interface design• Resource management• Security• Performance• Scalability• Interoperability

Page 7: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

7

Elements of good system architectures

• Internationalization/localization• Input/output• Error processing• Fault tolerance• Architectural feasibility• Robustness• Buy-versus-build decisions• Reuse decisions• Change strategy• General architectural quality

Page 8: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

8

General architectural quality

• Good architecture looks natural and easy• Objectives should be clearly stated• Motivations for all decisions clearly stated• Machine and language independent• Parts of the architecture should not receive more attention

than deserved• Identify & explain risk areas, indicate steps taken to

minimize risks• Architecture should contain multiple views of system• Programmer should be comfortable with architecture

Page 9: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

9

Design errors occur if

• The design is not self-consistent

• The design and the specification are not consistent

• The design and the requirements are not consistent

Page 10: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

10

Avoiding design errors

• Detect inconsistencies early– Late detection = more difficult and costly to correct

errors

• Verify– Design checked against the specification

– “Are we building the product right”

• Validate– Design checked against the user requirements

– “Are we building the right product”

Page 11: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

11

Fundamental Design Principles

• Simplicity

• Modularity

• Information hiding

Page 12: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

12

Simplicity“A design should be as simple as possible, but

no simpler”Albert Einstein

• Added extras & fancy trimmings might detract from the design’s purpose

• A simple design supports – Maintainability– Testability– Reliability– efficiency

Page 13: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

13

Modularity

• Divide system into smaller modules– grouping functionality

– Minimize interdependence

– Disadvantage of interdependency = one change can have many repercussions

• Orthogonal system – components highly independent (decoupled)

– Easier to design, build, test & extend

– Can improve reliability & efficiency

Page 14: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

14

Benefits of Modularity

• Increased Productivity

• Reduced Risk

Page 15: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

15

Modularity: - Increased productivity -

• Changes are localized– change one component without affecting another– Reduces development time & testing time

• Easy module replacement– Modules easily replaced with another, if necessary

• Easier development– Easier to write smaller, self-contained components– Each module captures one feature of a problem

• Promotes reuse– Components with specific, well-defined responsibilities can be

reused

Page 16: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

16

Modularity: - Reduced risk -

• Problem code is isolated– If code in module faulty – problem less likely to spread– Also easier to replace module with new one

• Reduced fragility – system less fragile– Any problems caused by small changes made to area

will be restricted to that area

• Increased testability– Easier to run tests on each component

• Increased flexibility

Page 17: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

17

Typical Layer Diagram

• Each layer hiding unnecessary detail

Page 18: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

18

Assessing modular structuring in SW• Coupling

– A measure of inter-module connectivity (the “form” and “strength” of the connection

– E.g. more desirable to have modules A & B communicating using parameters than sharing common data area (global variables)

• Cohesion– A measure of how “functionally related” the

components of the module are.– PrintReceipt module –code for printing the receipt

NOT code for recording the receipt of money

Page 19: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

19

Guidelines for creating software components (libraries of classes)

• Functionality– Component must have well-defined role

• Interfaces– Component must have well-defined interface

• Dependencies– Component should not have any context

specific dependencies– Existing dependencies should be clearly

specified

Page 20: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

20

Information hiding• Data structures within module to be

concealed from other software components• Direct access to data prevented• Data can be made accessible via

procedures, functions etc.

Stack class – data structure (stack) – hiddenClass methods Push & Pop allows stack to be

accessed

Page 21: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

21

Example designs NOT consistent with Fundamental Design

Principles• Many copies of “state” information - may lead to

inconsistencies in system behavior• Interface too complex – procedures or methods

with too many parameters• Excessively complex control structures• Unnecessary replication of information, duplicate

copies of information – passing complete record as parameter when only one field relevant

• Modules lacking functional strength – not well focused i.t.o focus

Page 22: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

22

Further Fundamental Design Principles

• Find real-world objects

• Form consistent abstractions

• Encapsulate implementation details

• Inherit – when inheritance simplifies the design

• Identify areas likely to change

• Look for common design patterns

Page 23: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

23

Find Real-World Objects

• Identify the objects (Employee & Client) and their attributes (data & methods: Name & UpdateAddress)

• Determine what operations can be performed on each object– Changing an employee’s title or billing rate

• Determine the parts of each object that will be visible to other objects– Public vs Private

• Define each object’s interface– Public & Protected

Page 24: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

24

Form Consistent Abstraction

• Abstraction– The ability to engage with a concept while

safely ignoring some of its irrelevant details– Allows developer to focus on interface without

having to worry about class’s internal workings

• The real world “door” example– Rectangular piece of material with hinges and a

doorknob / door handle– When using the door – not concerned with

individual fibers or workings of hinges or doorknob / door handle

Page 25: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

25

Encapsulate Implementation Details

• Abstraction allows you to look at the object at high level of detail

• Encapsulation prohibits you from looking at the object at any other level of detail – Hides the details of the complex concept

Page 26: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

26

• Allows a new class to be defined as a specialization of another class.– New class automatically inherits the features of

the class it is created from– Can add additional features or change or

suppress inherited features

Employee

PartTimeEmployee FullTimeEmployee

Inherit -When inheritance simplifies the design

Page 27: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

27

Identify areas likely to change

• Isolate areas likely to change to limit the effect of the change to one routine / class– Change thus confined to small area

Page 28: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

28

Common design patterns for a GOOD DESIGN

Most problems similar to past problemsThus, can be solved using similar solution/patterns• Simplicity

– “as simple as possible, but no simpler” design

• System Structure– Well structured design, consistent with modularity and

information hiding– Simplified using abstraction, encapsulation & inheritance

• Quality factors– Adhere to quality assessment criteria (Chapter 1)

Page 29: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

29

Design Practices

• Iterate

• Divide and conquer

• Top-down and bottom-up design approaches – composition strategy & decomposition strategy

• Collaborative design

• Capturing your design work (see next slide)

Page 30: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

30

Capturing your design work

• Insert design documentation into the code itself• Capture design discussions and decisions on Web

pages• Write e-mail summaries• Use a digital camera• Save design flip charts• Use CRC (Class, Responsibility, Collaborator) cards• Create UML diagrams at appropriate levels of detail

Page 31: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

31

Design Representations

• Help with the process of modeling the intended system and with evaluating its behavior.

• “black box” – describes what a system does

• “white box” – describes how it is to do it.

Page 32: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

32

Black Box representation - what

Page 33: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

33

White box representations - how

Page 34: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

34

Design Methods and Patterns

• Provide strategic guidance for the designer – Suggesting how to generate design solutions by

describing tasks to be performed and ordering sequence

Page 35: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

35

Design Methods and Patterns

Page 36: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

36

Design Methods and Patterns

• Standard ways of combining objects and classes to solve common design problems

• Offer generic solutions to a problem– By describing particular problem and– A strategy for addressing problem– Allowing designers to use solution repeatedly

• Example: The development of the arched bridge– Once basic idea established, model can be

adapted and extended to create variety of bridges: large, small, single or multiple arches.

Page 37: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

37

Design Methods and PatternsThe proxy design pattern

Page 38: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

38

Design Methods and PatternsThe proxy design pattern – Class Diagram

Page 39: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

39

Design Methods and Patterns

The proxy design pattern – Sequence Diagram

Page 40: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

40

Using a catalogue of Design Patterns

• Specify the problem• Select the category of pattern that is appropriate to

the design activity involved• Select the problem category appropriate to the

problem• Compare the problem description with the available

set of patterns taken from the selected category• Compare benefits and liabilities• Select the pattern variant that most fits the problem

Page 41: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

41

Prototyping

• Experimental, exploratory or evolutionary role• You can typically prototype:

– Architecture– New functionality in an existing system– Structure or contents of external data– Third party tools or components– Performance issues– User interface designs

Page 42: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

42

Experimental & Exploratory (Disposable) Prototypes

• You can ignore:– Correctness – use dummy data– Completeness – limited functionality of prototype– Robustness – error checking incomplete / missing– Style – little documentation besides details of

learning experience

Page 43: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

43

Evolutionary Prototypes

• Forms skeleton of final system

• Helps to get from a requirement to some aspect of final system quickly and visibly

• Not fully functional, but contains all error-checking, structuring, documentation etc.

• Allows for “fit for purpose” evaluation & easy adding of functionality

Page 44: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

44

Advantages of Evolutionary Prototypes

• Users get to see something working quickly

• Developers build a structure to work in

• You have an integration platform

• You have something to demonstrate

• You have a better feel for the program.

Page 45: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

45

Prototyping guidelines

• Dispose of disposable prototypes

• Prototyping for the client will demand the client’s time

• Choose appropriate tools

• Make sure everyone knows that the prototype is not the real deal

Page 46: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

46

The Specification Trap

• Specification will never capture every detail of a system or its requirements – users not 100% certain of their needs

• Diagramming techniques and formal methods are not always able to convey details in a natural way

• An overly descriptive design restricts the programmer

Page 47: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

47

Flexibility and Adaptability

• Scenario 1

During test phase, decided database system too slow – need to be changed to one from another vendor. How easily will this be to do? Is database access code entangled – will it be a nightmare to make the change.

Page 48: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

48

Flexibility and Adaptability

• Scenario 2

Project begins as client-server model. Later decided that servers are too expensive for some clients, they want a stand-alone version. How hard will it be for you to oblige?

Page 49: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

49

Duplicating Knowledge

• Follow the “don’t duplicate” principleCategories of duplication:• Imposed duplication

– Environment seems to make duplication unavoidable

• Inadvertent duplication– Developers introduce duplication without realising it

• Impatient duplication– Developers get lazy and duplicate as it seems easier.

• Inter-developer duplication– Information duplicated by multiple team members

Page 50: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

50

Gently exceeding your user’s expectations

• Balloon or ToolTip help• Keyboard shortcuts• A quick reference guide as a supplement to the user’s

manual• Colourisation• Log file analysers• Automated installation• Tools for checking the integrity of the system• The ability to run multiple versions of the system for training• A splash screen customized for their organization

Page 51: Best Practices. 2 How to design a Software Solution The plans or designs: –Represent the agreed upon needs of the user (“contract”) –Communicate what.

51

Further Principles and Practices

• Design and plan carefully

• Avoid complexity

• Make appropriate technology choices

• Etc.

• Etc.

• Etc.