美文网首页
OOD 小总结

OOD 小总结

作者: stepsma | 来源:发表于2016-11-14 13:17 被阅读0次

Singleton object:

只能生成一个instance, 就叫singleton object

public class CSingleton
{
   private static CSingleton instance;
   private CSingleton(){} 

   public static CSingleton getInstance(){
       if(instance== null){
          instance= new CSingleton();
       }
      return instance;
   }
};

调用时:

public class SingletonPatternDemo {
   public static void main(String[] args) {
      //Get the only object available
      CSingleton object = CSingleton.getInstance();
   }
}

下面是Singleton与static class的区别。
Singleton object stores in Heap but, static object stores in Stack
We can clone the object of Singleton but, we can not clone the static class object
Singleton class follow the OOP(object oriented principles) but not static class
we can implement interface with Singleton class but not with Static class.

其中什么是OOP:
https://chesterli0130.wordpress.com/2012/10/04/four-major-principles-of-object-oriented-programming-oop/

JAVA static变量:
记:static method 和 static variable 都不用创建 instance,可以类名直接引用。
http://crunchify.com/java-static-methods-variables-static-block-and-class-with-example/

http://blog.csdn.net/zhandoushi1982/article/details/8453522
static的好处是:全局唯一,一改都改。同时引用方便。
static final:全局固定常量

工厂模式:
http://blog.csdn.net/jason0539/article/details/23020989

使用不同factory to create 不同的class,product。Client just need to create the instance to factory. 不用考虑具体product是如何create,生产的。

产品:

abstract class BMW {  
    public BMW(){  
          
    }  
}  
public class BMW320 extends BMW {  
    public BMW320() {  
        System.out.println("制造-->BMW320");  
    }  
}  
public class BMW523 extends BMW{  
    public BMW523(){  
        System.out.println("制造-->BMW523");  
    }  
}  

工厂:

interface FactoryBMW {  
    BMW createBMW();  
}  
  
public class FactoryBMW320 implements FactoryBMW{  
  
    @Override  
    public BMW320 createBMW() {  
  
        return new BMW320();  
    }  
  
}  
public class FactoryBMW523 implements FactoryBMW {  
    @Override  
    public BMW523 createBMW() {  
  
        return new BMW523();  
    }  
}  

Client:

public class Customer {  
    public static void main(String[] args) {  
        FactoryBMW320 factoryBMW320 = new FactoryBMW320();  
        BMW320 bmw320 = factoryBMW320.createBMW();  
  
        FactoryBMW523 factoryBMW523 = new FactoryBMW523();  
        BMW523 bmw523 = factoryBMW523.createBMW();  
    }  
}  
State Machine Design Pattern

Similar to the State design pattern, a class behavior changes based on its state. And State Machine is the same as an intent of State: to make it possible for an object to alter its behavior when its internal state changes. It contains three main classes: State class, Event class, and Context class.

Context classes implements transition logic, and the next state is done by notifying the Context class with an event. State class transits to other state by passing Event to Context.

SNAKE原则

Scenario: case/interface
Necessary: constrain/hypothesis
Application: service/algorithm
Kilobit: Data
Evolve:

比如,design a FM Radio

Steps 1: Enumerate use cases,
Register/Login, Play Music, Music recommendation. 并说明,最重要的feature是什么。

Steps 2: Sort
Priority 1. Play Music
get channels, select channel, play music in this channel

相关文章

  • OOD 小总结

    Singleton object: 只能生成一个instance, 就叫singleton object 调用时:...

  • OOD

    系统设计的难点:如何为对象类分配职责对象之间如何协作什么样的类应该做什么样的事情 OO开发中至关重要的能力:熟练地...

  • 2019-06-17

    总结一下iOS的一些面试经验 1.面向对象的思想?(OOA OOD OOP) 面向对象的思...

  • OOD Detection

    这里其实与uncertainty预估有一定的关联性。对于ood或者shifting data,我们的目标就是能识别...

  • OOD与OOP的区别

    OOD:面向对象设计 面向对象设计(Object-Oriented Design,OOD)方法是OO方法中一个中间...

  • 专业术语解释

    1 OOD:面向对象设计(Object-Oriented Design,OOD)方法是OO方法中一个中间过渡环节。...

  • DDD -- 领域驱动设计 -- 面向对象(OOA/OOD)的缺

    OOA/OOD/OOP中,尤其是OOD/OOP,大家都不陌生,用了很多年。并且大部分人,都是从OOP开始,到了一定...

  • GeekBand笔记: C++面向对象高级编程(3)

    OOD(Object Oritented Design) Inheritance 继承表示 is-apublic,...

  • OO、OOD、OOA、OOP的定义

    很多人在求职的时候,会遇到一个这样的问题:“OOD/OOP是什么”,这个时候有人就会问OOD、OOP是什么呢?那么...

  • JAVA OOD 小结

    Primitive data type, and object data type Student s = new...

网友评论

      本文标题:OOD 小总结

      本文链接:https://www.haomeiwen.com/subject/jilfpttx.html