Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2019-05-10:请列出几种常见的工厂模式并说明它们的用法? #50

Open
Moosphan opened this issue May 10, 2019 · 8 comments

Comments

@Moosphan
Copy link
Owner

No description provided.

@MaskEgo
Copy link

MaskEgo commented May 10, 2019

单例模式,工厂模式,建造者模式,观察者模式

@MoJieBlog
Copy link
Collaborator

单例模式,工厂模式,建造者模式,观察者模式

这个是建造者模式了

@guosen
Copy link

guosen commented May 10, 2019

//简单工厂模式:
 public interface MyAbInterca{
    public void a();
}

public class MyInterceImplement implement MyAbInterca{
    .......
}

//工厂方法模式:
public abstract class Product {
    public abstract void method();
}
public class ConcreteProductA extends Product {
    @Override
    public void method() {
        System.out.println("产品A");
    }
}
public class ConcreteProductB extends Product {
    @Override
    public void method() {
        System.out.println("产品B");
    }
}
//抽象工厂模式:
public abstract void method();
}
/**

具体产品类A
*/
public class ConcreteProductA extends Product {
     @Override
     public void method() {
          System.out.println(“我是具体的产品A”);
     }
}


具体产品类B
*/
public class ConcreteProductB extends Product {
    @Override
    public void method() {
        System.out.println(“我是具体的产品B”);
    }
}

@YangSimon
Copy link

单例模式
工厂模式

@yangfanggang
Copy link

打卡打卡

去了解一下

@LvKang-insist
Copy link

@MrCodeSniper
Copy link

工厂模式
1.简单工厂(杂而不精)
一个工厂方法根据参数的不同创建不同的对象 (多重ifelse)
2.工厂方法(过于专一)
一个工厂负责生产一个具体对象(太多工厂类的使用)
3.抽象工厂(职责分离又不缺灵活)
通过参数选取不同的工厂生产对象

@yline
Copy link

yline commented Jan 6, 2020

举个案例:
ArrayList 和 HashMap 都间接实现了 Iterable方法
然后每一个Iterable方法返回一个产品实例

这就是一个工厂模式的案例;使用就是统一的foreach遍历

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants