Giter VIP home page Giter VIP logo

design-patterns's Introduction

Quick Remind

Class Relations

  1. Association
  • represent a bi-directional relationship: one student play many sports, a sport can be played by many student
  • No ownership: student doesn't own sport
  • No lifecycle dependency: If one object is destroyed, the other can continue to exist - If one student stop playing, sport still exist. vice versa
public class Student{
	public void play(Sport: sport){
		execute.play(sport);
	}
}
  1. Aggregation
  • week has-a relationship: a whole has parts that belongs to it
  • no lifecycle dependency: exist independent
class Airliner{
	private ArrayList<CrewMember> crew;

	public Airliner(){
		crew = new ArrayList<CrewMember>();
	}

	public void add(CrewMember crewMember){}
}
  • airliner have 0 or many crew members
  • can add crew members latter
  1. Composition
  • Strong has-a relationship => access parts through its whole
  • Part exclusive belong to whole
  • Lifecycle dependency
public class House{
	private Room room;
	public House(){
		room = new Room();
	}
}
  • room created at the same time with the House
  1. Dependency
  • represent a relationship where change in one class may affect another class
  • Doesn't imply structural relationships but rather a reliance
  • Car depend on Fuel but NO ownership or direct association
class Car{
	public void start(Fuel fuel){}
}

class Fuel{

}

UML

Class Diagram

Design Pattern

Creation Patterns

Singleton pattern

  1. Intent
  • one instance
  • provide global access to this instance
  1. Implement
  • private static field for singleton instance
  • private constructor
  • public static creation method to get instance

Factory Method

  • Concrete Instantiation

design-patterns's People

Contributors

toxtung avatar

Watchers

Tung To 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.