There are three main categories of 23 design patterns:
Create five types of models: Factory method mode, abstract Factory mode, singleton mode, builder mode, prototype mode.
Structure mode, a total of seven kinds: Adapter mode, adorner mode, proxy mode, appearance mode, bridging mode, combined mode, enjoy the meta-mode.
There are 11 types of behavioral Patterns: Strategy mode, template method mode, observer mode, iteration sub-mode, responsibility chain mode, Command mode, Memo mode, state mode, visitor mode, mediator mode, interpreter mode.
1 PackageCom.example.main;2 3 Importandroid.app.Activity;4 ImportAndroid.content.Context;5 ImportAndroid.os.Bundle;6 Importandroid.widget.LinearLayout;7 ImportAndroid.widget.TextView;8 9 /*Ten * Android design mode--singleton mode (Singleton) One */ A - Public classSingletonextendsActivity { - the PrivateLinearLayout ly; - Privatelinearlayout Sly; - - @Override + protected voidonCreate (Bundle savedinstancestate) { - Super. OnCreate (savedinstancestate); + Setcontentview (r.layout.create); A atly =(LinearLayout) Findviewbyid (r.id.creately); -Sly =(LinearLayout) Findviewbyid (r.id.singly); - -Android Google =NewAndroid ("Google", Ly, This); - google.setname (); - inAndroid Huawei =NewAndroid ("Huawei", Ly, This); - huawei.setname (); to + //First instantiation -iOS iOS = ios.getinstance ("Apple", Sly, This); the ios.setname (); * $ //Second CallPanax NotoginsengIOS Samsung = ios.getinstance ("Samsung", Ly, This); - samsung.setname (); the } + A /* the * Android Manufacturer + */ - $ classandroid{ $ - PrivateString name; - PrivateLinearLayout ly; the PrivateTextView TV; - Privatecontext context;Wuyi the PublicAndroid (String name,linearlayout ly,context Context) { - This. Name =name; Wu This. ly =ly; - This. Context =context; About } $ - Public voidSetName () { -TV =NewTextView (context); - This. Tv.settext (name + "Android Device"); A This. Ly.addview ( This. TV); + } the } - $ /* the * Apple Manufacturers the */ the the Static classios{ - in PrivateString name; the PrivateLinearLayout ly; the PrivateTextView TV; About Privatecontext context; the the //Prohibit references the + Private StaticIOS instance =NULL; - the //private constructors to prevent instantiation. Bayi the PrivateIOS () {} the - PrivateIOS (String name,linearlayout ly,context Context) { - This. Name =name; the This. ly =ly; the This. Context =context; the } the - //Create an instance the the Public StaticIOS getinstance (String name,linearlayout ly,context Context) { the 94 if(Instance = =NULL) { theInstance =NewIOS (name,ly, context); the } the returninstance;98 } About - Public voidSetName () {101TV =NewTextView (context);102Tv.settext ("iOS only belongs to" +name+ "Company");103 Ly.addview (TV);104 } the }106}View Code
Android design mode--singleton mode (Singleton)