Upgrade to Pro — share decks privately, control downloads, hide ads and more …

OO Design

OO Design

A quick intro to OO Design.

Josh Comer

May 10, 2013
Tweet

More Decks by Josh Comer

Other Decks in Programming

Transcript

  1. Why Object Oriented? There are many approaches to software design:

    • Procedural (C, FORTRAN) • Functional (Haskell, OCaml, Clojure) • Object Oriented (Java, Objective-C) Java is designed to be an Object Oriented (OO) language. OO allows developer to easily create abstractions and reason about their software.
  2. A Few Things to Remember • There isn't a single

    correct way to design your software. • Good OO design is tricky, so don't worry if you don't get it perfect the first time. Programming is not about typing, it's about thinking. The sooner you realize that, the sooner you'll become a better programmer. -Rich Hickey
  3. How to communicate design When working with other people on

    a project, everyone needs to be on the same page. UML was created to allow people to clearly communicate software design. By using UML, we can spend more time thinking and less time explaining.
  4. Class Diagram Class Name + fieldOne : int - fieldTwo

    : String ~ FieldThree : float # FieldFour : Object + methodOne(int a, int b) : int - methodTwo() : void Title is bold for concrete classes; italics for abstract classes; and surrounded by <> for interfaces Fields are listed along with their type. + Public - Private ~ Package # Protected Methods include parameters (with types) and the type of the return value
  5. Where to start when designing 1. Understand the requirements (almost

    to the point of memorization) 2. Try to list out all of the potential objects required to fulfil the requirements 3. Look for overlaps in your defined objects 4. Map out your software using UML ◦ Remember to keep extensibility and maintenance in mind 5. Double check that your design meets the original requirements
  6. Program to an 'interface', not an 'implementation' -Gang of Four

    "Program to an interface" really means "Program to a supertype". -Head First Design Patterns
  7. Design Principles The following design principles are important to keep

    in mind when designing OO software: • Open Closed Principle (OCP) • Don't Repeat Yourself (DRY) • Single Responsibility Principle (SRP) • Liskov Substitution Principle (LSP)
  8. Things in an RPG • Player ◦ Class ◦ Inventory

    ◦ Money ◦ Equipment • Items ◦ Weapons ◦ Spells ◦ Money ◦ Armour • Monsters ◦ Equipment ◦ Type ◦ Drop Items • NPC ◦ Conversation • Dungeons ◦ Treasure Chests ◦ Monsters
  9. Not all objects are "real" It is easy to only

    design for objects that have real world counterparts. You will find when designing software that "real" objects are typically in the minority. Examples of non-"real" objects are: • Streams (Input, Output, etc) • Connection Managers • Data Structures