Ch 7: Object Oriented Design Flashcards
Important Concepts
- Object Oriented Programming
- Class Diagrams
- Inheritance
- OOP Design Steps
- Design Patterns
What are Design Patterns?
Goal of good Object Oriented Design
To create elegant, maintainable code arranged into objects.
Design is NOT about regurgitating known Design Patterns.
Object Oriented Design Steps
- Handle Ambiguity
- Define Core objects
- Analyze Relationships
- Investigate Actions
Object Oriented Design Steps:
1. Handle Ambiguity
Questions/Problems are often vague(intentionally in interviews, less intentionally in real life)
Ask Clarifying questions:
* Use the “Six W’s”:
- WHO is going to use it
- WHAT
- WHY
- WHERE will it be used
- WHEN will it be used (time, frequency of use, etc)
- HOW are they going to use it
Object Oriented Design Steps:
2. Define Core Objects
- Determine what the most fundamental objects should be, can be revised as the process goes on
- Objects may represent real world counterparts(user, company, building, etc)
- Objects may be abstract: (session, time block, requests, etc)
Object Oriented Design Steps:
3. Analyze Relationships
- Consider the relationships between the objects created so far
- Which are “members” of other objects
- Which objects inherent from a parent object(or could)
- Is the relationship many-to-one, many-to-many, one-to-one?
Object Oriented Design Steps:
4. Investigate Actions
Assess the Key Actions that objects take, and how they relate to other objects.
Likely to have forgotten some objects
Design Patterns:
Two Extremely Common Design Patterns in Interviews
- Singleton
- Factory Pattern
(Note: you should know many more design patterns than these)
Singleton Pattern:
Overview
- Ensures that a class has only one instance
- Ensures access to the instance through the application
- Useful for “global” objects with exactly one instance
- Many people dislike the Singleton design pattern
- Sometimes called an “anti-pattern”
- Can sometimes interfere with Unit Testing
Factory Design Pattern:
Overview
- Offers an interface for creating an instance of a class
- Subclasses decide WHICH class to instantiate
- Factory method takes a parameter representing WHICH class to instantiate
- Constructs and returns an instance of the specified class
- Typically has a Creator class
- Either abstract or concrete with an implementation of the Factory method
OOP Design Principles:
10 Key Principles
- DRY (Don’t Repeat Yourself)
- Encapsulate What Changes
- Open Closed Design Principle
- Single Responsibility Principle(SRP)
- Dependency Injection or Inversion Principle
- Favor Composition over Inheritance
- Liskov Substitution Principle (LSP)
- Interface Segregation Principle (ISP)
- Programming for Interface not Implementation
- Delegation Principles
Page: https://hackernoon.com/10-oop-design-principles-every-programmer-should-know-f187436caf65