10
Object-Oriented Design

Object-Oriented Design. Object Oriented Design CRC stands for Classes, Responsibilities, Collaborators Class name goes on the top Responsibilities go

Embed Size (px)

Citation preview

Page 1: Object-Oriented Design. Object Oriented Design CRC stands for Classes, Responsibilities, Collaborators Class name goes on the top Responsibilities go

Object-Oriented Design

Page 2: Object-Oriented Design. Object Oriented Design CRC stands for Classes, Responsibilities, Collaborators Class name goes on the top Responsibilities go

Object Oriented Design

CRC stands for Classes, Responsibilities, Collaborators

Class name goes on the top Responsibilities go on the left Collaborators go on the right

Page 3: Object-Oriented Design. Object Oriented Design CRC stands for Classes, Responsibilities, Collaborators Class name goes on the top Responsibilities go

UML Basics

Inherits, is a...

Implements, is a...

Aggregation, has a...

Dependency

Page 4: Object-Oriented Design. Object Oriented Design CRC stands for Classes, Responsibilities, Collaborators Class name goes on the top Responsibilities go

Design

Identify nouns Group nouns into packages Responsibilities Identify more nouns & responsibilities Use case - example that helps identify what the

program needs to do/handle

Page 5: Object-Oriented Design. Object Oriented Design CRC stands for Classes, Responsibilities, Collaborators Class name goes on the top Responsibilities go

Testing

It's a good idea to write unit tests, small examples of things that should happen

Language feature: assert()

Page 6: Object-Oriented Design. Object Oriented Design CRC stands for Classes, Responsibilities, Collaborators Class name goes on the top Responsibilities go

Documentation

/** javadoc comment */ put them on classes, methods, fields, as

appropriate @see refer to another class or method @param document a param @return document the return value

Page 7: Object-Oriented Design. Object Oriented Design CRC stands for Classes, Responsibilities, Collaborators Class name goes on the top Responsibilities go

Examples

Blackjack? Chess? Battleship? Adventure?

Page 8: Object-Oriented Design. Object Oriented Design CRC stands for Classes, Responsibilities, Collaborators Class name goes on the top Responsibilities go

Debugging

To debug:

compile with the -g flag, javac -g Prog.java

To run the debugger

local debugging

jdb Prog remote debugging

java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8080 Prog

jdb -attach 8080 To profile:

run like this: java -agentlib:hprof Prog

then start jconsole and attach to your program

Page 9: Object-Oriented Design. Object Oriented Design CRC stands for Classes, Responsibilities, Collaborators Class name goes on the top Responsibilities go

Debugging

stop at BlackJackViewer:58 sets breakpoint

clear BlackJackViewer:58 clears breakpoint

dump bj / print bj.game.deck.cards.size() prints out variables

run / step / step up / next / cont

Page 10: Object-Oriented Design. Object Oriented Design CRC stands for Classes, Responsibilities, Collaborators Class name goes on the top Responsibilities go

Debugging

threads / thread locals set watch threads where