Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 18: More Design Work

Similar presentations


Presentation on theme: "Lecture 18: More Design Work"— Presentation transcript:

1 Lecture 18: More Design Work
CSE 542 – Software Engineering Concepts

2 What Have We Done? Figured out what clients wants project to do
Elicited client’s needs & wrote into documents Collect important terms & definitions in dictionary Wrote requirements recording work that could occur Be careful with user stories; many never implemented Use cases more reliable, only used when cost justified These requirement documents will drive rest of project

3 First Design Step

4 Second Design Step

5 Classes (usually) are nouns (things); Methods are verbs (actions)
OO Key Concept #1 Classes (usually) are nouns (things); Methods are verbs (actions)

6 Third Design Step Designing classes next step in process
For each class, start by determining fields from above Link classes that work together so easy to code When done well, coding becomes relatively simple What should be fields & how can we know? Since they are abstract, boundary classes often fields Control classes often fields; something must use it Read text again: look where noun possesses another

7 Liskov Substitution Principle
Named after inventor – Barbara Liskov Determines if generalization is appropriate Subtypes must be usable anywhere supertype used

8 LSP In Practice Square is regular geometric shape with 4 sides
Also have rectangles which need length & width Which is subclass and which should be superclass? Rectangle As Superclass Square As Superclass Square Is-A Rectangle Just force equal length & width Reverse untrue: Rectangle Is-A Square Rectangle Is-A Square Easy to use Rectangle as Square Reverse untrue: Square not always usable as Rectangle

9 LSP In Practice Square is regular geometric shape with 4 sides
Also have rectangles which need length & width Which is subclass and which should be superclass? Rectangle As Superclass Square As Superclass Square Is-A Rectangle Just force equal length & width Reverse untrue: Rectangle Is-A Square Rectangle Is-A Square Easy to use Rectangle as Square Reverse untrue: Square not always usable as Rectangle

10 Single Responsibility Principle
Goal of every class & method written Make sure that class represents single concept Methods perform single action & not “bucket of mud” Many benefits accrue when code follows SRP Easier to write code, since design becomes simpler More focused results make debugging a snap Modifying design quicker when changes needed

11 No Free Cheeseburgers Achieving SRP means 1 last step in design
More classes & methods often created by this process But also create smaller, simpler classes & methods Less total time required even with this "extra" step To get SRP, people found CRC cards are easiest 3x5 cards & a brain are all this process takes

12 CRC Cards Explained Divide 3x5 Card into 3 parts
Class name from UML design document Responsibilities are the methods class will need Collaborations are classes it will interact with

13 Responsibilities Initially you should start with actions you found
Add facts class knows, since these are getter methods If class should not be responsible, move action Instead, the action placed in class where makes sense Make classes collaborators after action moved Pays off in long run, but may make new classes now

14 How to know if responsibility logical?
Responsibilities Initially you should start with actions you found Add facts class knows, since these are getter methods If class should not be responsible, move action Instead, the action placed in class where makes sense Make classes collaborators after action moved Pays off in long run, but may make new classes now How to know if responsibility logical?

15 Seriously! Go Yourself

16 If the Responsibility Fits
Try each responsibility into following statement Find that statements valid only if responsibility fits The (class name) (responsibility) itself Move actions to class that works in statement The (new class) (responsibility) (old class)

17 Let’s Try It For Car Which of these responsibilities belong to car
Starts engine Kills engine Changes tires Gets driven Gets washed Changes oil Warns oil is low Reports on fuel level

18 Let’s Try It For Car Which of these responsibilities belong to car
Starts engine Kills engine Changes tires Gets driven Gets washed Changes oil Warns oil is low Reports on fuel level

19 Let’s Try It For Car Which of these responsibilities belong to car
Starts engine Kills engine Changes tires Gets driven Gets washed Changes oil Warns oil is low Reports on fuel level

20 Let’s Try It For Car Which of these responsibilities belong to car
Starts engine Kills engine Changes tires Gets driven Gets washed Changes oil Warns oil is low Reports on fuel level

21 Let’s Try It For Car Which of these responsibilities belong to car
Starts engine Kills engine Changes tires Gets driven Gets washed Changes oil Warns oil is low Reports on fuel level

22 Let’s Try It For Car Which of these responsibilities belong to car
Starts engine Kills engine Changes tires Gets driven Gets washed Changes oil Warns oil is low Reports on fuel level

23 Let’s Try It For Car Which of these responsibilities belong to car
Starts engine Kills engine Changes tires Gets driven Gets washed Changes oil Warns oil is low Reports on fuel level

24 Let’s Try It For Car Which of these responsibilities belong to car
Starts engine Kills engine Changes tires Gets driven Gets washed Changes oil Warns oil is low Reports on fuel level

25 Let’s Try It For Car Which of these responsibilities belong to car
Starts engine Kills engine Changes tires Gets driven Gets washed Changes oil Warns oil is low Reports on fuel level

26 Reality Is Important… Team rarely keeps project from start to end
Only in smaller groups lacking engineering teams Developers specialize skills & become more efficient Documents transmitting knowledge very important People quit & new people added into on-going projects Course needs to provide real-world experiences Documents must be usable when teammates move on Pickup material using information in Git Handle real changes more than on-boarding grade

27 Time To Change Partners
Distribute new team lists

28 How Will You Handle This?

29 How Will You Handle This?

30 Why do I have to work with [other team]?
What's Next? Why do I have to work with [other team]? What did I do wrong?

31 Where Does This Apply? Cricket/Baseball Buffalo Weather
Passion Threshold Buffalo Weather Suck Threshold Baseball/Cricket

32 Where Does This Apply? App’s UI Cricket/Baseball Buffalo Weather
Passion Threshold Buffalo Weather Suck Threshold Baseball/Cricket

33 Where Does This Apply? App’s UI Libraries Cricket/Baseball
Passion Threshold Buffalo Weather Suck Threshold Baseball/Cricket

34 Where Does This Apply? App’s UI Libraries Use Cases Design
Cricket/Baseball Passion Threshold Buffalo Weather Suck Threshold Baseball/Cricket

35 Where Does This Apply? App’s UI Libraries Use Cases Design
Anytime you have users Cricket/Baseball Passion Threshold Buffalo Weather Suck Threshold Baseball/Cricket

36 Win Users & Influence People
Only a few minutes to make first impression Do not lose time by making user read manuals Entice user with an clear, obvious utility Get users to payoff as quickly as possible Make their journey’s first steps obvious Common metaphors make it easy to start Look familiar? This slide is paraphrased from the UI lecture!

37 Avoid Fear & Loathing Artifacts nearly always written exactly once
Ignore writers viewpoint – they will never use work Focus on the many others reading & using artifacts Save time in long run by using common metaphors The quicker they understand the more they like you Focus on user & avoid annoying questions Remind them that their work will be handed to people less talented than them. If they need to convince the code monkeys of the workability of their design, they lose time

38 Keep It Simple, Idiot

39 Keep It Simple

40 Intuitive Is Key Making users think is preying on their weakness
Time spent thinking == time cursing you out Users assume that everything has a purpose Scroll lock & human appendix still get discussed Users assume a purpose, why else would it exist? Unused methods & parameters create guessing game What is the meaning of method’s return value?

41 Make It Intuitive Remain consistent when using metaphor: Customer.placesOrder(Order toGo) Customer.knowsAddress() Customer.addToDatabase() Customer.initialize() Slide could just as easily be for classes, UI, use cases, more…

42 Make It Intuitive Remain consistent when using metaphor: Customer.placesOrder(Order toGo) Customer.knowsAddress() Customer.addToDatabase() Customer.initialize() Slide could just as easily be for classes, UI, use cases, more…

43 Delegation Delegation improves composition of classes
Goal creating classes & code easier to write, read, & use Not universal solution, but useful additional tool Important for writing code that works as people expect Replace getters & add methods for needed actions Methods can act, but mostly delegate to field's methods Adds (slightly) to code size, but performance unchanged Trade-off worth it, since we write once but use frequently

44 Delegation Key Concept
Image of Homer Simpson used under Parody & Fair Use exceptions. Original from:

45 Delegation Example public class FullName { private String firstName; private String lastName; // Constructor, getters & setters also here } public class Student { private FullName name; // Brevity is the soul of wit- Shakespeare public FullName getName() { return name; } // In some other code that exists to demonstrate this point Student student = /* Code to create and initialize a Student instance*/ FullName fName = student.getName(); fName.setLastName("Jingleheimerschmidt");

46 Replace yuck-inducing getter method…
Delegation Example public class FullName { private String firstName; private String lastName; // Constructor, getters & setters also here } public class Student { private FullName name; // Brevity is the soul of wit- Shakespeare public FullName getName() { return name; } // In some other code that exists to demonstrate this point Student student = /* Code to create and initialize a Student instance*/ FullName fName = student.getName(); fName.setLastName("Jingleheimerschmidt"); Replace yuck-inducing getter method…

47 Delegation Example public class FullName { private String firstName; private String lastName; // Constructor, getters & setters also here } public class Student { private FullName name; // Brevity is the soul of wit- Shakespeare public void setFirstName(String newName) { name.setFirstName(newName); } // In some other code that exists to demonstrate this point Student student = /* Code to create and initialize a Student instance*/ FullName fName = student.getName(); fName.setLastName("Jingleheimerschmidt"); Replace yuck-inducing getter method… … with method calling field's method

48 Reducing how much you must understand…
Delegation Example public class FullName { private String firstName; private String lastName; // Constructor, getters & setters also here } public class Student { private FullName name; // Brevity is the soul of wit- Shakespeare public void setFirstName(String newName) { name.setFirstName(newName); } // In some other code that exists to demonstrate this point Student student = /* Code to create and initialize a Student instance*/ FullName fName = student.getName(); fName.setLastName("Jingleheimerschmidt"); Reducing how much you must understand…

49 Delegation Example public class FullName { private String firstName; private String lastName; // Constructor, getters & setters also here } public class Student { private FullName name; // Brevity is the soul of wit- Shakespeare public void setFirstName(String newName) { name.setFirstName(newName); } // In some other code that exists to demonstrate this point Student student = /* Code to create and initialize a Student instance*/ student.setLastName("Jingleheimerschmidt"); Reducing how much you must understand… …so writing & updating code becomes easier!

50 Composition + Delegation =
public class FullName { private String firstName; private String lastName; // Constructor, getters & setters also here } public class Student { private FullName name; // Brevity is the soul of wit- Shakespeare public void setFirstName(String newName) { name.setFirstName(newName); } // In some other code that exists to demonstrate this point Student student = /* Code to create and initialize a Student instance*/ student.setLastName("Jingleheimerschmidt");

51 Composition Key Concept #1
When relationship between classes is Has a(n): Add fields & Delegate actions

52 Make It Intuitive Easiest to follow when names & usage are parallel String.compareTo(String str) String.compareToIgnoreCase(String str) Slide could just as easily be for classes, UI, use cases, more…

53 Make It Intuitive Easiest to follow when names & usage are parallel String.compareTo(String str) String.compareToIgnoreCase(String str) String.equals(String str) String.equalsIgnoreCase(String str) Slide could just as easily be for classes, UI, use cases, more…

54 Make It Intuitive Easiest to follow when names & usage are parallel String.compareTo(String str) String.compareToIgnoreCase(String str) String.equals(String str) String.equalsIgnoreCase(String str) String.regionMatches(boolean iC,String str) String.regionMatchesIgnoreCase(String str) Slide could just as easily be for classes, UI, use cases, more…

55 Make It Intuitive Easiest to follow when names & usage are parallel String.compareTo(String str) String.compareToIgnoreCase(String str) String.equals(String str) String.equalsIgnoreCase(String str) String.regionMatches(boolean iC,String str) String.regionMatchesIgnoreCase(String str) Slide could just as easily be for classes, UI, use cases, more…

56 Make It Intuitive Easiest to follow when names & usage are parallel String.compareTo(String str) String.compareToIgnoreCase(String str) String.equals(String str) String.equalsIgnoreCase(String str) String.regionMatches(boolean ignoreCase, …) String.regionMatchesIgnoreCase(String str) Slide could just as easily be for classes, UI, use cases, more…

57 Make Their Lives Easier
[P]erfection is attained not when there is nothing left to add, but when there is nothing left to remove Move to the next slide to better make M. de Sant-Exusperry’s point

58 Make Their Lives Easier
[P]erfection … is nothing left to remove Discuss concerns over complexity of GUI designs in quizzes; remind students of the quote from the little prince Discuss quizzes (to be handed back at end) and my reasoning for the results

59 Project teams are unchanged
I Lied… Project teams are unchanged


Download ppt "Lecture 18: More Design Work"

Similar presentations


Ads by Google