Object Oriented Programming Flashcards
1
Q
4 Major Principles of OOP
A
- inheritance
- polymorphism
- abstraction
- encapsulation
2
Q
abstract class
A
- a class that you only inherit from
- you don’t directly instantiate from
3
Q
polymorphism
A
- 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
Q
encapsulation
A
- the process of hiding information pertaining to an object from the client
5
Q
UML
Class Diagrams
A
- unified modeling language
3 parts
- class name
- attributes
- visibility - name - colon - datatype
- method
- visibility - name - parens - args - colon - return type
6
Q
OOP Design
Steps
A
- focus on what, not how
Steps
- Obtain/prepare textual description of problem
- Underline nouns => classes
- Underline adjectives => attributes
- Underline active verbs => methods
- Flesh out the requirements
- Identify classes
- Underline nouns
- Identfy attributes
- Underline adjectives
- Use domain knowledge
- Identify oeprations
- Underline active verbs
- Examine interactions among entities
- Identify major entities
- Define bahaviors (methods) for each major entity
- Identity sub-entities
- Define behaviors for each sub-entity
- Define relationships between entitties
7
Q
interaction between objects
A
3 main types
- x uses (depends on) y: dependency
- x has y: association/aggregation/composition:
- x is a y: generalization (inheritance)
8
Q
association
A
- 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
Q
aggregation
A
- 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
Q
composition
A
- 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
Q
generalization
A
- a type of OOP relationship
- an ‘IS-a’ relationship
- basically inheritance
- Notation:
- solid line, open triangle
- subclass to superclass
12
Q
dependency
A
- x uses y
- if y changes, x might change
13
Q
A