工厂方法模式

来源:互联网 发布:中国大数据信息 编辑:程序博客网 时间:2024/06/07 20:44
package com.lantier.xxb_student.drawlayerlayout.factory;/** * Created by xxb_student on 2017/5/20. */public abstract class Factory {    public abstract WindowStyle createWindowStyle();

}

package com.lantier.xxb_student.drawlayerlayout.factory;/** * Created by xxb_student on 2017/5/20. */public class MacThemeFactory extends Factory {    @Override    public WindowStyle createWindowStyle() {        return new MacWindowStyle();    }}



package com.lantier.xxb_student.drawlayerlayout.factory;import android.util.Log;/** * Created by xxb_student on 2017/5/20. */public class MacWindowStyle extends WindowStyle {    private static final String TAG = "MacWindowStyle";    @Override    public void useThisStyle() {        Log.d(TAG, "---->>useThisStyle:MacWindowStyle ");    }}



package com.lantier.xxb_student.drawlayerlayout.factory;import android.util.Log;/** * Created by xxb_student on 2017/5/20. */public class UbuntuWindowStyle extends WindowStyle {    private static final String TAG = "UbuntuWindowStyle";    @Override    public void useThisStyle() {        Log.d(TAG, "---->>useThisStyle:UbuntuWindowStyle ");    }}


package com.lantier.xxb_student.drawlayerlayout.factory;/** * Created by xxb_student on 2017/5/20. */public abstract class WindowStyle {    public abstract void useThisStyle();}



package com.lantier.xxb_student.drawlayerlayout.factory;import android.util.Log;/** * Created by xxb_student on 2017/5/20. */public class WindowsWindowStyle extends WindowStyle {    private static final String TAG = "WindowsWindowStyle";    @Override    public void useThisStyle() {        Log.d(TAG, "---->>useThisStyle: WindowsWindowStyle");    }}



private void init() {    Factory factory = new MacThemeFactory();    WindowStyle windowStyle = factory.createWindowStyle();    windowStyle.useThisStyle();}




05-20 15:06:04.610 1197-1197/com.lantier.xxb_student.drawlayerlayout D/MacWindowStyle: ---->>useThisStyle:MacWindowStyle 

原创粉丝点击