Coder Social home page Coder Social logo

srgrace / object-oriented-design Goto Github PK

View Code? Open in Web Editor NEW
10.0 2.0 2.0 40 KB

Object-Oriented system design.

Home Page: https://srgrace.github.io/Object-Oriented-Design/

License: GNU General Public License v3.0

C++ 100.00%
oops-to-devops oops-in-java system-design object-oriented-programming oops-in-cpp

object-oriented-design's Introduction

Object-Oriented-Design

Object-Oriented system design i.e sketch out the classes and methods to implement technical problems or real-life objects.

How to Approach

Step 1: Handle Ambiguity

  • Make assumptions or, ask clarifying questions.
  • Go through "six W's": who, what, where, when, how, why.

Step 2: Define the Core Objects

Suppose we are asked to do the object-oriented design for a restaurant. Our core objects might be things like Table, Guest, Party, Order, Meal, Employee, Server, and Host etc.

Step 3: Analyse Relationships

Ask questions like...

Which objects are members of which other objects?
Do any objects inherit from any others?
Are relationships one-to-many or many-to-many?

For example, Restaurant design:

  • Party should have an array of Guests.
  • Server and Host inherit from Employee.
  • Each Table has one Party, but each Party may have multiple Tables.
  • There is one Host for the Restaurant.

Step 4: Investigate Actions

At this point, we have the basic outline of the object-oriented design. Now, we have to consider key actions that the objects will take and how they relate to each other. Add and update some forgotten objects, if possible.

Design Patterns

Singleton Class (Can interfere with unit testing)

The singleton pattern ensures that a class has only one instance and ensures access to the instance through the application.
OR The singleton pattern is a design pattern that restricts the instantiation of a class to one object.
Example:

public class Restaurant 
{
    private static Restaurant _instance = null;
    protected Restaurant() { .... }
    public static Restaurant getInstance() 
    {
        if(_instance == null)
            _instance = new Restaurant();
            
        return _instance;
    }
}

Factory Mathod

The Factory Method offers an interface for creating an instance of a class, with its sub-classes deciding which class to instantiate.
Example:

public class CardGame
{
    public static CardGame createCardGame(GameType type)
    {
        if(type == GameType.Poker)
            return new PokerGame();
            
        else if(type == GameType.BlackJack)
            return new BlackJackGame();
            
        return null;
    }
}

object-oriented-design's People

Contributors

srgrace avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.