设计模式03-抽象工厂

一、介绍

抽象工厂属于创建型模式,它的特点是将创建方法延迟到子类,每个工厂可以生产多个产品。

二、类图分析

在这里插入图片描述
IViewFactory:父工厂,视图工厂的顶层接口类
AndroidViewFactory:具体工厂类,生产android相关的视图
IOSViewFactory:具体工厂类,生产IOS相关的视图
IButton:父产品,button的接口类
ITextView:父产品,与IButton一致,同一产品族
AndroidButton,IOSButton:具体的产品类,IButton的实现类
AndroidTextView,IOSTextView:具体的产品类,ITextView的实现类

三、代码实现

public interface IViewFactory {
   IButton createButton();
   ITextView createTextView();
}
public class AndroidViewFactory implements IViewFactory {
   public IButton createButton(){
		return new AndroidButton();
	}
   public ITextView createTextView(){
		return new AndroidTextView();
	}
}
public class IOSViewFactory implements IViewFactory {
   public IButton createButton(){
		return new IOSButton();
	}
   public ITextView createTextView(){
		return new IOSTextView();
	}
}
public interface IButton {
   void show();
}
public interface ITextView{
   void show();
}
public class AndroidButton implements IButton {
	void show(){

	}
}
public class AndroidTextView implements IButton {
	void show(){

	}
}
public class IOSButton implements IButton {
	void show(){

	}
}
public class IOSTextView implements IButton {
	void show(){

	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值