118
Design CMPT 373 Soſtware Development Methods Nick Sumner [email protected]

Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Design

CMPT 373Software Development Methods

Nick [email protected]

Page 2: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What is design?

● Not referring to UX (even though it’s important)

Page 3: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What is design?

● Not referring to UX (even though it’s important)

● Includes many things:

Page 4: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What is design?

● Not referring to UX (even though it’s important)

● Includes many things:– The components of the system

Audio

Input

Network Persistence

Graphics

ClientLogic

ServerLogic

Page 5: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What is design?

● Not referring to UX (even though it’s important)

● Includes many things:– The components of the system

– How they interact

Audio

Input

Network Persistence

Graphics

ClientLogic

ServerLogic

Page 6: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What is design?

● Not referring to UX (even though it’s important)

● Includes many things:– The components of the system

– How they interact ?

Page 7: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What is design?

● Not referring to UX (even though it’s important)

● Includes many things:– The components of the system

– How they interact architecture

Page 8: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What is design?

● Not referring to UX (even though it’s important)

● Includes many things:– The components of the system

– How they interact

– The interfaces & abstractions they expose (or hide!)

Page 9: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What is design?

● Not referring to UX (even though it’s important)

● Includes many things:– The components of the system

– How they interact

– The interfaces & abstractions they expose (or hide!)

What is an abstraction?

Page 10: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What is design?

● Not referring to UX (even though it’s important)

● Includes many things:– The components of the system

– How they interact

– The interfaces & abstractions they expose (or hide!)

Server server{port};while (true) { auto incoming = server.receive(); ... server.send(outgoing);}

What does the networking librarythat I gave to you expose/hide?

Page 11: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What is design?

● Not referring to UX (even though it’s important)

● Includes many things:– The components of the system

– How they interact

– The interfaces & abstractions they expose (or hide!)

Is design UML?

Page 12: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What is design?

● Not referring to UX (even though it’s important)

● Includes many things:– The components of the system

– How they interact

– The interfaces & abstractions they expose (or hide!)

Is design UML?

Is UML design?

Page 13: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Why does design matter?

Page 14: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Why does design matter?

● Translating requirements and stories to code

As a XI can YSo that ZAs a X

I can YSo that ZAs a X

I can YSo that ZAs a X

I can YSo that ZAs a X

I can YSo that Z

PerformanceAvailability

Security...

Design

/////////////////////////////////////////////////////////////////////////////// Single Threaded Networking//// This file is distributed under the MIT License. See the LICENSE file// for details./////////////////////////////////////////////////////////////////////////////

#include <unistd.h>#include "ChatWindow.h"#include "Client.h"

intmain(int argc, char* argv[]) { if (argc < 3) { printf("Usage:\n%s <ip address> <port>\ne.g. %s localhost 4002\n", argv[0], argv[0]); return 1; }

networking::Client client{argv[1], argv[2]};

bool done = false; auto onTextEntry = [&done, &client] (std::string text) { if ("exit" == text || "quit" == text) { done = true; } else { client.send(text); } };

ChatWindow chatWindow(onTextEntry); while (!done && !client.isDisconnected()) { try { client.update(); } catch (std::exception& e) { chatWindow.displayText("Exception from Client update:"); chatWindow.displayText(e.what()); done = true; }

auto response = client.receive(); if (!response.empty()) { chatWindow.displayText(response); } chatWindow.update(); }

return 0;}

Page 15: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Why does design matter?

● Translating requirements and stories to code

● Understandability

Page 16: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Why does design matter?

● Translating requirements and stories to code

● Understandability

How much time do professionalprogrammers spend reading code?

Page 17: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Why does design matter?

● Translating requirements and stories to code

● Understandability

● Performance & reliability

Page 18: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Why does design matter?

● Translating requirements and stories to code

● Understandability

● Performance & reliability

● Reusability

Page 19: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Why does design matter?

● Translating requirements and stories to code

● Understandability

● Performance & reliability

● Reusability

● Determines ease & risk for change.

Page 20: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Why does design matter?

● Translating requirements and stories to code

● Understandability

● Performance & reliability

● Reusability

● Determines ease & risk for change.– Understanding of requirements will change

Page 21: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Why does design matter?

● Translating requirements and stories to code

● Understandability

● Performance & reliability

● Reusability

● Determines ease & risk for change.– Understanding of requirements will change

– Requirements will change

Page 22: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Why does design matter?

● Translating requirements and stories to code

● Understandability

● Performance & reliability

● Reusability

● Determines ease & risk for change.– Understanding of requirements will change

– Requirements will change

– Your code may outlast your time at a company

Page 23: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Why does design matter?

● Translating requirements and stories to code

● Understandability

● Performance & reliability

● Reusability

● Determines ease & risk for change.– Understanding of requirements will change

– Requirements will change

– Your code may outlast your time at a company

● Once software is too complex to reason about,it is too late

Page 24: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design bad?

● Too many possible ways to design poorly to list

Page 25: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design bad?

● Too many possible ways to design poorly to list

● Common attributes of a bad design: [Ousterhout 2018]

Page 26: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design bad?

● Too many possible ways to design poorly to list

● Common attributes of a bad design: [Ousterhout 2018]

– Change AmplificationAn apparently simple change requires modifying many locations

Page 27: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design bad?

● Too many possible ways to design poorly to list

● Common attributes of a bad design: [Ousterhout 2018]

– Change AmplificationAn apparently simple change requires modifying many locations

– Cognitive LoadThe developer needs to know a great deal in order to complete a task

Page 28: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design bad?

● Too many possible ways to design poorly to list

● Common attributes of a bad design: [Ousterhout 2018]

– Change AmplificationAn apparently simple change requires modifying many locations

– Cognitive LoadThe developer needs to know a great deal in order to complete a task

– Unknown unknownsPotions of code to modify for a task may be hard to identify

Page 29: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design bad?

● Too many possible ways to design poorly to list

● Common attributes of a bad design: [Ousterhout 2018]

– Change AmplificationAn apparently simple change requires modifying many locations

– Cognitive LoadThe developer needs to know a great deal in order to complete a task

– Unknown unknownsPotions of code to modify for a task may be hard to identify

These are symptoms of complexity.

Page 30: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design good?

● It identifies & manages complexity– Inherent (essential) complexity

Page 31: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design good?

● It identifies & manages complexity– Inherent (essential) complexity

– Incidental (accidental) complexity

Page 32: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design good?

● It identifies & manages complexity– Inherent (essential) complexity

– Incidental (accidental) complexity

hide

Page 33: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design good?

● It identifies & manages complexity– Inherent (essential) complexity

– Incidental (accidental) complexity

minimize

hide

Page 34: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design good?

● It identifies & manages complexity– Inherent (essential) complexity

– Incidental (accidental) complexity

● What is complexity?

Page 35: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design good?

● It identifies & manages complexity– Inherent (essential) complexity

– Incidental (accidental) complexity

● What is complexity?– No agreed upon universal definition; many variants

Page 36: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design good?

● It identifies & manages complexity– Inherent (essential) complexity

– Incidental (accidental) complexity

● What is complexity?– No agreed upon universal definition; many variants

– Grows as entities/concepts in project are connected/woven together

Page 37: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design good?

● It identifies & manages complexity– Inherent (essential) complexity

– Incidental (accidental) complexity

● What is complexity?– No agreed upon universal definition; many variants

– Grows as entities/concepts in project are connected/woven together

[Watch “Simple Made Easy” for one interesting perspective]

Page 38: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design good?

● It identifies & manages complexity– Inherent (essential) complexity

– Incidental (accidental) complexity

● What is complexity?– No agreed upon universal definition; many variants

– Grows as entities/concepts in project are connected/woven together

[Watch “Simple Made Easy” for one interesting perspective]– One other heuristic is risk of change

Page 39: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design good?

Broadly

● Divides the system into independent components

Page 40: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design good?

Broadly

● Divides the system into independent components

● Makes it easy for developers to get their jobs done

Page 41: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design good?

● Not clever

Page 42: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design good?

● Not clever!

int x = foo(bar(baz(bam(a), b), c), d);

Page 43: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design good?

● Not clever!!

// this subroutine is called thousands of times.// use longjmp instead of loops to increase speed.

voidcalculate(struct salesinfo* sales){ jmp_buf buffer; int i=setjmp(buffer); if (!(i<sales->count)) RETURN_NOTHING; addvaluetosubtotal(sales->values[i]); if (i<sales->count) longjmp(buffer,i+1);}

int x = foo(bar(baz(bam(a), b), c), d);

http://thedailywtf.com/articles/Longjmp--FOR-SPEED!!!

Page 44: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design good?

● Not clever!!!

// this subroutine is called thousands of times.// use longjmp instead of loops to increase speed.

voidcalculate(struct salesinfo* sales){ jmp_buf buffer; int i=setjmp(buffer); if (!(i<sales->count)) RETURN_NOTHING; addvaluetosubtotal(sales->values[i]); if (i<sales->count) longjmp(buffer,i+1);}

int x = foo(bar(baz(bam(a), b), c), d);

http://thedailywtf.com/articles/Longjmp--FOR-SPEED!!!

Page 45: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design good?

● Not clever

● Loose coupling

vs

Page 46: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design good?

● Not clever

● Loose coupling

vs

Why?

Page 47: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design good?

● Not clever

● Loose coupling

– Content (accessing implementation of another component)

Page 48: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design good?

● Not clever

● Loose coupling

– Content (accessing implementation of another component)

...goto yourcode... ...

yourcode:...

Page 49: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design good?

● Not clever

● Loose coupling

– Content (accessing implementation of another component)– Common global data

Page 50: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design good?

● Not clever

● Loose coupling

– Content (accessing implementation of another component)– Common global data

int global = ...

global = ...

int global = ...

global = ...

... = global

... = global

Page 51: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design good?

● Not clever

● Loose coupling

– Content (accessing implementation of another component)– Common global data

int global = ...

global = ...

int global = ...

global = ...

... = global

... = global

Page 52: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design good?

● Not clever

● Loose coupling

– Content (accessing implementation of another component)– Common global data

int global = ...

global = ...

int global = ...

global = ...

... = global

... = globalSingletons have these constraints and worse.

Page 53: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design good?

● Not clever

● Loose coupling

– Content (accessing implementation of another component)– Common global data

– Subclassing

We will spend a day in the future on this.

Page 54: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design good?

● Not clever

● Loose coupling

– Content (accessing implementation of another component)– Common global data

– Subclassing

– Temporal

Page 55: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design good?

● Not clever

● Loose coupling

– Content (accessing implementation of another component)– Common global data

– Subclassing

– Temporal

Cat cat = new Cat;...delete cat;

Page 56: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design good?

● Not clever

● Loose coupling

– Content (accessing implementation of another component)– Common global data

– Subclassing

– Temporal

Cat cat = new Cat;...delete cat;

Process p;p.doStep1();p.doStep2();p.doStep3();

Page 57: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design good?

● Not clever

● Loose coupling

– Content (accessing implementation of another component)– Common global data

– Subclassing

– Temporal

Cat cat = new Cat;...delete cat;

Process p;p.doStep1();p.doStep2();p.doStep3();

This is more insidious!

Process p;p.foo();p.bar();p.baz();

Page 58: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design good?

● Not clever

● Loose coupling

– Content (accessing implementation of another component)– Common global data

– Subclassing

– Temporal

– Passing data to/from each other

Page 59: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design good?

● Not clever

● Loose coupling

– Content (accessing implementation of another component)– Common global data

– Subclassing

– Temporal

– Passing data to/from each other

x = foo(1,2)def foo(a, b): ...

Page 60: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design good?

● Not clever

● Loose coupling

– Content (accessing implementation of another component)– Common global data

– Subclassing

– Temporal

– Passing data to/from each other

– Independence

Page 61: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design good?

● Not clever

● Loose coupling

● High fan in / low fan out

foo()

bar() baz()

vsfoo()

bar()

Page 62: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design good?

● Not clever

● Loose coupling

● High fan in / low fan out

foo()

bar() baz()

vsfoo()

bar()

Do you agree?Why?

Page 63: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design good?

● Not clever

● Loose coupling

● High fan in / low fan out

● Layers / Stratification

Page 64: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design good?

● Not clever

● Loose coupling

● High fan in / low fan out

● Layers / Stratification

& a consistent, self contained view per level

Page 65: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design good?

● Not clever

● Loose coupling

● High fan in / low fan out

● Layers / Stratification

New / GreenfieldCode

Wrapper API

Legacy / Sketchy Code

Page 66: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design good?

● Not clever

● Loose coupling

● High fan in / low fan out

● Layers / Stratification

New / GreenfieldCode

Wrapper API

External Library

Page 67: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design good?

● Not clever

● Loose coupling

● High fan in / low fan out

● Layers / Stratification

New / GreenfieldCode

Wrapper API

External Library

What impact does this have oninvariants & types?

Page 68: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design good?

● Not clever

● Loose coupling

● High fan in / low fan out

● Layers / Stratification

● Cohesion

● ...

vs

Page 69: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What makes a design good?

● Not clever

● Loose coupling

● High fan in / low fan out

● Layers / Stratification

● Cohesion

● ...

But these are the ends, not the means

Page 70: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Revisiting Complexity

● We can characterize causes of complex designs [Ousterhout 2018]

Page 71: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Revisiting Complexity

● We can characterize causes of complex designs [Ousterhout 2018]

– DependenciesCode cannot be understood in isolation because of relationships to other code.

Page 72: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Revisiting Complexity

● We can characterize causes of complex designs [Ousterhout 2018]

– DependenciesCode cannot be understood in isolation because of relationships to other code.

– ObscurityImportant information about code is not obvious.

Page 73: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Revisiting Complexity

● We can characterize causes of complex designs [Ousterhout 2018]

– DependenciesCode cannot be understood in isolation because of relationships to other code.

– ObscurityImportant information about code is not obvious.

These directly relate to thequalities of good code we just saw.

Page 74: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Consider a design

UserInterface Graphics

DataStorage

BusinessLogic

EnterpriseBackbone

Page 75: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Consider a design

UserInterface Graphics

DataStorage

BusinessLogic

EnterpriseBackbone

Is this simple? Why?

Page 76: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Consider a design

● What if you want to modify the business logic?

UserInterface Graphics

DataStorage

BusinessLogic

EnterpriseBackbone

Page 77: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Consider a design

● What if you want to modify the business logic?

● What if you want to reuse the business logic?

UserInterface Graphics

DataStorage

BusinessLogic

EnterpriseBackbone

Page 78: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Consider a design

● What if you want to modify the business logic?

● What if you want to reuse the business logic?

● What if you want to replace the display?

UserInterface Graphics

DataStorage

BusinessLogic

EnterpriseBackbone

Page 79: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Consider a design

● What if you want to modify the business logic?

● What if you want to reuse the business logic?

● What if you want to replace the display?

UserInterface Graphics

DataStorage

BusinessLogic

EnterpriseBackbone

Like a basket woven together,you get everything or nothing.

Page 80: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Consider a design

Graphics

DataStorage

BusinessLogic

EnterpriseBackbone

UserInterface

Page 81: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Consider a design

Is this simpler? Why?

Graphics

DataStorage

BusinessLogic

EnterpriseBackbone

UserInterface

Page 82: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Consider a design

What is still complex? Why?Is this simpler? Why?

Graphics

DataStorage

BusinessLogic

EnterpriseBackbone

UserInterface

Page 83: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Consider a design

● The fewer connected or conflated concepts, the better

Page 84: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Consider a functionboolisFasterThanSound(double speed) { return speed > MACH1;}

Page 85: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Consider a functionboolisFasterThanSound(double speed) { return speed > MACH1;}

Is this simple or complex? Why?

Page 86: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

boolisFasterThanSound(double speed) { return speed > MACH1;}

(double speed, double angle) {

}

Consider a function

Is this simple or complex? Why?

Page 87: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Consider a functionboolisFasterThanSound(double speed) { return speed > MACH1;}

A good design should be hard to misuse

(double speed, double angle) {

}Is this simple or complex? Why?

Page 88: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Consider a classclass Student {public: ... ID getID() const; Name getName() const; Address getAddress() const;

void storeToDatabase() const; static Student readFromDatabase();

bool canApplyForCoOp(); bool meetsDegreeRequirements();};

Page 89: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Consider a classclass Student {public: ... ID getID() const; Name getName() const; Address getAddress() const;

void storeToDatabase() const; static Student readFromDatabase();

bool canApplyForCoOp(); bool meetsDegreeRequirements();};What is good about this class?

Page 90: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Consider a classclass Student {public: ... ID getID() const; Name getName() const; Address getAddress() const;

void storeToDatabase() const; static Student readFromDatabase();

bool canApplyForCoOp(); bool meetsDegreeRequirements();};What is good about this class? What is bad about this class?

Page 91: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What are our simplifying tools?

● Metaphors – identify “real world” objects & relations

Page 92: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What are our simplifying tools?

● Metaphors – identify “real world” objects & relations

Be careful.This can be a good place to start,

but a poor place to end.

Page 93: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What are our simplifying tools?

● Metaphors – identify “real world” objects & relations

● Abstraction – use high level concepts

Page 94: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What are our simplifying tools?

● Metaphors – identify “real world” objects & relations

● Abstraction – use high level concepts

● Encapsulation – hide the details

This is the Code Complete definition,not a universal one!

Page 95: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What are our simplifying tools?

● Metaphors – identify “real world” objects & relations

● Abstraction – use high level concepts

● Encapsulation – hide the details

Deeply tied to information hiding

Page 96: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What are our simplifying tools?

● Metaphors – identify “real world” objects & relations

● Abstraction – use high level concepts

● Encapsulation – hide the details

● Consistency

Page 97: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What are our simplifying tools?

● Metaphors – identify “real world” objects & relations

● Abstraction – use high level concepts

● Encapsulation – hide the details

● Consistency

● Inheritance?

Page 98: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What are our simplifying tools?

● Metaphors – identify “real world” objects & relations

● Abstraction – use high level concepts

● Encapsulation – hide the details

● Consistency

● Inheritance?– In small, constrained doses

– Ideally through interfaces

Page 99: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

What are our simplifying tools?

● Metaphors – identify “real world” objects & relations

● Abstraction – use high level concepts

● Encapsulation – hide the details

● Consistency

● Inheritance?– In small, constrained doses

– Ideally through interfaces

Use especially for:1) likely/risky to change code2) frequently used code

Page 100: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Key Strategy: Mitigate change

● Identify potential areas of change

class Student {public: ... int getID() const; ...};

Page 101: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Key Strategy: Mitigate change

● Identify potential areas of change

class Student {public: ... int getID() const; ...};

Page 102: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Key Strategy: Mitigate change

● Identify potential areas of change

● Separate them structurally

class Student {public: ... int getID() const; ...};

Page 103: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Key Strategy: Mitigate change

● Identify potential areas of change

● Separate them structurally

class Student {public: ... ID getID() const; ...};

class Student {public: ... int getID() const; ...};

Page 104: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Key Strategy: Mitigate change

● Identify potential areas of change

● Separate them structurally

● Isolate their impact through interfaces

Page 105: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Key Strategy: Mitigate change

● Identify potential areas of change

● Separate them structurally

● Isolate their impact through interfaces

class IDCreator {public: ... virtual ID createID() = 0; ...};

Page 106: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Key Strategy: Mitigate change

... ID studentID = student.getID(); ...

How might this hinder change?

Page 107: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Key Strategy: Mitigate change

... ID studentID = student.getID(); ...

How might this hinder change?

How can it be resolved?

Page 108: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Key Strategy: Mitigate change

... ID studentID = student.getID(); ...

How might this hinder change?

How can it be resolved?

What are the trade offs?

Page 109: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Constant Vigilance

● Avoiding complexity requires a planned process

Page 110: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Constant Vigilance

● Avoiding complexity requires a planned process– Code review everything

[metaphors, abstraction, encapsulation, consistency, inheritance]

Page 111: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Constant Vigilance

● Avoiding complexity requires a planned process– Code review everything

[metaphors, abstraction, encapsulation, consistency, inheritance]– Write tests (simple code is easier to test)

Page 112: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Constant Vigilance

● Avoiding complexity requires a planned process– Code review everything

[metaphors, abstraction, encapsulation, consistency, inheritance]– Write tests (simple code is easier to test)

● Know when & where you make bad decisions

– technical debt

Page 113: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Constant Vigilance

● Avoiding complexity requires a planned process– Code review everything

[metaphors, abstraction, encapsulation, consistency, inheritance]– Write tests (simple code is easier to test)

● Know when & where you make bad decisions

– technical debt● You end up paying it back!

Page 114: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Design Smells

● A design smell is a clue that better design is needed

Page 115: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Design Smells

● A design smell is a clue that better design is needed

● Such as: (adapted from John Ousterhout)

– Thin components● Is it really hiding an implementation?● Is complexity arising from having to many small classes?

Page 116: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Design Smells

● A design smell is a clue that better design is needed

● Such as: (adapted from John Ousterhout)

– Thin components● Is it really hiding an implementation?● Is complexity arising from having to many small classes?

– Information leaks● Can I see the implementation details? (unintentional interface)● Repeated similar code

Page 117: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Design Smells

● A design smell is a clue that better design is needed

● Such as: (adapted from John Ousterhout)

– Thin components● Is it really hiding an implementation?● Is complexity arising from having to many small classes?

– Information leaks● Can I see the implementation details? (unintentional interface)● Repeated similar code

– Difficulty making a change

Page 118: Design - Simon Fraser Universitywsumner/teaching/373/03-design.pdf · What is design? Not referring to UX (even though it’s important) Includes many things: – The components of

Experience

● Experience hones your sense of design.– Hopefully, our discussions this semester will help you be aware of it.