Object Oriented Programming Flashcards Preview

General > Object Oriented Programming > Flashcards

Flashcards in Object Oriented Programming Deck (13):
1

4 Major Principles of OOP

  • inheritance
  • polymorphism
  • abstraction
  • encapsulation

2

abstract class

  • a class that you only inherit from
  • you don't directly instantiate from

3

polymorphism

  • The ability of a subclass to also act as an instance of its own superclass
  • Ex:
    • Superclass -> Shape
    • Subclasses-> Squares, Triangles
    • You can create an array of shapes and safely fill it with squares and triangles
  • Every triangle/square/circle is also a shape

4

encapsulation

  • the process of hiding information pertaining to an object from the client

5

UML

Class Diagrams

  • unified modeling language

3 parts

  • class name
  • attributes
    • visibility - name - colon - datatype
  • method
    • visibility - name - parens - args - colon - return type

6

OOP Design

Steps

  • focus on what, not how

Steps

  1. Obtain/prepare textual description of problem
  2. Underline nouns => classes
  3. Underline adjectives => attributes
  4. Underline active verbs => methods

 

 

  1. Flesh out the requirements
  2. Identify classes
    1. Underline nouns
  3. Identfy attributes
    1. Underline adjectives
    2. Use domain knowledge
  4. Identify oeprations
    1. Underline active verbs
    2. Examine interactions among entities

 

  1. Identify major entities
  2. Define bahaviors (methods) for each major entity
  3. Identity sub-entities
  4. Define behaviors for each sub-entity
  5. Define relationships between entitties

7

interaction between objects

3 main types

  1. x uses (depends on) y: dependency
  2. x has y: association/aggregation/composition:
  3. x is a y: generalization (inheritance)

8

association

  • a type of OOP relationship
  • a Has-a relationship
  • two objects have a relationship, but they can exist independently of each other
  • there is no ownership or lifetime dependency
  • ex: doctor and patient
  • Notation
    • Solid line
    • Describe relation with text

9

aggregation

  • a type of OOP relationship
  • a 'Has-a' relationship
  • A special type of association which describes a whole and its parts
  • The parts can exist ouside of the whole
  • ex: a baseball team and players
  • Notation
    • Solid lne, open diamond
    • Part to whole

10

composition

  • a type of OOP relationship
  • a 'has a' relationship
  • there is ownership
  • when owner is destroyed, child is destroyed
  • both ownership and lifetime dependency
  • ex: house and room
  • ex: class and inner class
  • Notation:
    • Solid line, closed diamond
    • Part to whole

11

generalization

  • a type of OOP relationship
  • an 'IS-a' relationship
  • basically inheritance
  • Notation:
    • solid line, open triangle
    • subclass to superclass

12

dependency

  • x uses y
  • if y changes, x might change

13