csc 212 – data structures
DESCRIPTION
CSC 212 – Data Structures. Lecture 8: Object-Oriented Design. Your Goal When Writing Classes. Good programs work Everything else is secondary Best way for code to work is reusing code Old code has already been debugged Redesigning the wheel wastes time. Good programs work. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: CSC 212 – Data Structures](https://reader035.vdocument.in/reader035/viewer/2022062309/5681476b550346895db4a862/html5/thumbnails/1.jpg)
CSC 212 –Data Structures
Lecture 8:
Object-Oriented Design
![Page 2: CSC 212 – Data Structures](https://reader035.vdocument.in/reader035/viewer/2022062309/5681476b550346895db4a862/html5/thumbnails/2.jpg)
Your Goal When Writing Classes
Good programs workGood programs work Everything else is secondary
Best way for code to work is reusing code Old code has already been debugged Redesigning the wheel wastes time
![Page 3: CSC 212 – Data Structures](https://reader035.vdocument.in/reader035/viewer/2022062309/5681476b550346895db4a862/html5/thumbnails/3.jpg)
Great Designs in History
Hide complexity but keep functionalityProvide enough details to use class only
Cars only leave critical controls visible
![Page 4: CSC 212 – Data Structures](https://reader035.vdocument.in/reader035/viewer/2022062309/5681476b550346895db4a862/html5/thumbnails/4.jpg)
Encapsulation
Keep class details private Never expose fields
Makes changing their definitions simple Do not specify how methods work
Specify what they do, insteadLeaves you free to rewrite methods
Limiting public info simplifies using classKeeps design general & improves reuse
![Page 5: CSC 212 – Data Structures](https://reader035.vdocument.in/reader035/viewer/2022062309/5681476b550346895db4a862/html5/thumbnails/5.jpg)
Great Designs in History
Design should not specify useShould adapt to any environment
Legos place few limits on how used
![Page 6: CSC 212 – Data Structures](https://reader035.vdocument.in/reader035/viewer/2022062309/5681476b550346895db4a862/html5/thumbnails/6.jpg)
Abstraction
Describe design in simple, easy languageEach noun should be a classEach action should be its own public method
Use absolutely minimum number of fieldsNo fields for values that can be computedMake type of each field as open as possible
Do not let how enter your design until last step
![Page 7: CSC 212 – Data Structures](https://reader035.vdocument.in/reader035/viewer/2022062309/5681476b550346895db4a862/html5/thumbnails/7.jpg)
Great Designs in History
Design should be easy to modifyEnable easy modification as needs change
Quick & easy modifications of components
![Page 8: CSC 212 – Data Structures](https://reader035.vdocument.in/reader035/viewer/2022062309/5681476b550346895db4a862/html5/thumbnails/8.jpg)
Modularity
Classes represent single concept/actorUse classes/fields to provide extra details
Each method should do only 1 thingBreak complex actions into small, private
methodsLimit reliance on any implementation details
Always separate input & output from methods that actually do anything I/O details change frequently
![Page 9: CSC 212 – Data Structures](https://reader035.vdocument.in/reader035/viewer/2022062309/5681476b550346895db4a862/html5/thumbnails/9.jpg)
Choosing Classes
Examine from functional point of view Questions to ask:
What are the actors? (What interacts in system?)
What does each actor do? Where do actors interact? Whose goals or
needs are being met?
![Page 10: CSC 212 – Data Structures](https://reader035.vdocument.in/reader035/viewer/2022062309/5681476b550346895db4a862/html5/thumbnails/10.jpg)
Unified Modeling Language
Illustrate system's classes & relationships Provides class diagram
Class nameAttributes (Fields)Operations (Methods)
![Page 11: CSC 212 – Data Structures](https://reader035.vdocument.in/reader035/viewer/2022062309/5681476b550346895db4a862/html5/thumbnails/11.jpg)
Unified Modeling Language
Illustrate system's classes & relationships Provides class diagram
Class nameAttributes (Fields)Operations (Methods)
Basis of tracing formatBecome more useful as
class continues
![Page 12: CSC 212 – Data Structures](https://reader035.vdocument.in/reader035/viewer/2022062309/5681476b550346895db4a862/html5/thumbnails/12.jpg)
Unified Modeling Language
Can show relationships between actorsUseful for dividing into fine grained classes
![Page 13: CSC 212 – Data Structures](https://reader035.vdocument.in/reader035/viewer/2022062309/5681476b550346895db4a862/html5/thumbnails/13.jpg)
Your Turn
Groups will be changing (starting today) Do not like things getting too static and boring New groups courtesy of random.org
Group 1 Group 2 Group 3
Jaydon Okan Jim
Ryan Alison Debbie
Kim Abe Ben
Derrick Katey Tim
Jake
![Page 14: CSC 212 – Data Structures](https://reader035.vdocument.in/reader035/viewer/2022062309/5681476b550346895db4a862/html5/thumbnails/14.jpg)
Before Next Lecture…
Finish lab #2 Finish week #3 assignment Start programming assignment #1
It is due 2 weeks from today Mondays’s lecture discusses inheritance
Read Section 2.2 of the book