csc 212 – data structures

14
CSC 212 – Data Structures Lecture 8: Object-Oriented Design

Upload: ellery

Post on 13-Jan-2016

36 views

Category:

Documents


0 download

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 Presentation

TRANSCRIPT

Page 1: CSC 212 – Data Structures

CSC 212 –Data Structures

Lecture 8:

Object-Oriented Design

Page 2: CSC 212 – Data Structures

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

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

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

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

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

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

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

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

Unified Modeling Language

Illustrate system's classes & relationships Provides class diagram

Class nameAttributes (Fields)Operations (Methods)

Page 11: CSC 212 – Data Structures

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

Unified Modeling Language

Can show relationships between actorsUseful for dividing into fine grained classes

Page 13: CSC 212 – Data Structures

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

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