首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

好久没来了。散分,23种设计模式。必须要有代码说明。解决办法

2013-01-26 
好久没来了。散分,23种设计模式。必须要有代码说明。每人最多写一种,帮顶也给分。[解决办法]看出来了。。。纯散分

好久没来了。散分,23种设计模式。必须要有代码说明。
每人最多写一种,帮顶也给分。
[解决办法]
看出来了。。。纯散分的~
[解决办法]
呵呵 飘过 接分 
[解决办法]

我就来接接分。。。。那东西三二次话就想明白难。。
[解决办法]
工厂模式。路过绝代不经常来了
[解决办法]

接分来的
[解决办法]
看出来了。。。纯散分的~
[解决办法]
帮顶,LZ好人,多给点哈好久没来了。散分,23种设计模式。必须要有代码说明。解决办法
[解决办法]
纯散分的
[解决办法]
路过 顺便接个分 (*^__^*) 嘻嘻……
谢谢楼主
[解决办法]
迭代器模式



foreach(var item in (new List<int>(){ 1 , 2 , 3 }))
{
    Console.WriteLine(item);
}


[解决办法]
   简单工厂...
            路过。
[解决办法]
简单抽象工厂
[解决办法]
工厂模式
public class DaoFactory {

private static UserDao userDao = null;
private static DaoFactory instance = new DaoFactory();

private DaoFactory() {
try {
Properties prop = new Properties();

InputStream inStream = DaoFactory.class.getClassLoader()
.getResourceAsStream("daoconfig.properties");

prop.load(inStream);
String userDaoClass = prop.getProperty("userDaoClass");
Class clazz = Class.forName(userDaoClass);
userDao = (UserDao) clazz.newInstance();
} catch (Throwable e) {
throw new ExceptionInInitializerError(e);
}
}

public static DaoFactory getInstance() {
return instance;
}

public UserDao getUserDao() {
return userDao;
}
}

[解决办法]
观察者模式



public class Button
{
    public event EventHandler Click;
}


[解决办法]
单态模式
private static singlet instance=new singlet();


public static singlet getinstance{
return instance;}
[解决办法]

引用:
有多少人能在不参考资料的情况下完整的写出抽象工厂的代码(包括伪代码,uml图)。能写出来的请举手。

可以给我们讲一下这些模式么?
哈哈!
[解决办法]
命令模式:

// Command pattern -- Structural example  
using System; 
// "Command" 
abstract class Command 

 // Fields 
 protected Receiver receiver; 
 // Constructors 
 public Command( Receiver receiver ) 
 { 
  this.receiver = receiver; 
 } 
 // Methods 
 abstract public void Execute(); 


// "ConcreteCommand" 
class ConcreteCommand : Command 

 // Constructors 
 public ConcreteCommand( Receiver receiver ) : 
  base ( receiver ) {} 
 // Methods 
 public override void Execute() 
 { 
  receiver.Action(); 
 } 


// "Receiver" 
class Receiver 

 // Methods 
 public void Action() 
 { 
  Console.WriteLine("Called Receiver.Action()"); 
 } 


// "Invoker" 
class Invoker 

 // Fields 
 private Command command; 
 // Methods 
 public void SetCommand( Command command ) 
 { 
  this.command = command; 
 } 
 public void ExecuteCommand() 
 { 
  command.Execute(); 
 } 


//// <summary> 
/// Client test 
/// </summary> 
public class Client 

 public static void Main( string[] args ) 
 { 
  // Create receiver, command, and invoker 
  Receiver r = new Receiver(); 
  Command c = new ConcreteCommand( r ); 
  Invoker i = new Invoker(); 
  // Set and execute command 
  i.SetCommand(c); 
  i.ExecuteCommand(); 
 } 


[解决办法]
引用:
有多少人能在不参考资料的情况下完整的写出抽象工厂的代码(包括伪代码,uml图)。能写出来的请举手。

我第一个举不了。。。。。
[解决办法]
没分就不能提问吧??
[解决办法]
引用:
有多少人能在不参考资料的情况下完整的写出抽象工厂的代码(包括伪代码,uml图)。能写出来的请举手。

看资料都看的云里雾里,哎。。。。
[解决办法]
多顶,多顶哦
[解决办法]
单例模式
[解决办法]
我想下载一个速达软件啊
[解决办法]
思维 与 经验...
互补 互斥
------解决方案--------------------


先顶蹭分先
[解决办法]
帮顶,纯接分,

[解决办法]
学习中,接分,谢楼主
[解决办法]
好久没来了。散分,23种设计模式。必须要有代码说明。解决办法

引用:
看出来了。。。纯散分的~

[解决办法]
好吧,第一反应,BS写单件设计模式的.
[解决办法]
我是来顶的,接分啊
[解决办法]
《大话设计模式》
[解决办法]
不回答模式。。。
[解决办法]
<a href="www.baidu.com">大话设计模式</a>
[解决办法]
看出来了,纯散分的!
[解决办法]
工厂模式是最常用的!
[解决办法]
路过 接分 谢谢
[解决办法]
接分模式
[解决办法]
Mark  学习 
[解决办法]
jfjff
[解决办法]
不懂模式
[解决办法]
路过!!听说这里有分拿
[解决办法]
监听者模式    
来接分的... 
[解决办法]
帮顶+看代码
[解决办法]
mark + 接分
[解决办法]
哇塞   不懂这个啊

[解决办法]
帮顶,顺便接分!
[解决办法]
哈哈,正没有分了
[解决办法]
打酱油模式
[解决办法]
我要一个模态的
 顺便接分
[解决办法]
开放-闭合原则
[解决办法]
帮顶,顺便接分!
[解决办法]
引用:
《大话设计模式》
这书我看过。语言其实不幽默,难道我笑点太高?
[解决办法]
工厂     纯顶的。。。
[解决办法]
2011年5月软件设计师考的是combine模式。
菜单包含子菜单,子菜单再分子菜单。。。。
[解决办法]
散分是一种奉献,更是一种资本.
[解决办法]
哈哈 我喜欢这个!
[解决办法]
 单例模式


public class Singleton{

public static Singleton instance;

private Singleton(){}

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

}
[解决办法]
看起来还有好多要学~~~
[解决办法]
来一个适配器模式~


/**
 *  A interface
 */
public interface Shape  {
    public void Draw();
    public void Border();
}

/**
 *  The Adaptee in this sample
 */
public class Text  {
    private String content; 
    public Text() {
        
    }
    public void SetContent(String str) {
        content = str;
    }
    public String GetContent() {
        return content;
    }
}

/**
 *  The Object Adapter in this sample 
 */
public class TextShapeObject  implements Shape {
    private Text txt;
    public TextShapeObject(Text t) {
        txt = t;
    }
    public void Draw() {
        System.out.println("Draw a shap ! Impelement Shape interface !");
    }
    public void Border() {
        System.out.println("Set the border of the shap ! Impelement Shape interface !");
    }
    
    public void SetContent(String str) {
        txt.SetContent(str);
    }
    public String GetContent() {
        return txt.GetContent();;
    }

    public static void main(String[] args) {
        Text myText = new Text();
        TextShapeObject myTextShapeObject = new TextShapeObject(myText);
        myTextShapeObject.Draw();
        myTextShapeObject.Border();
        myTextShapeObject.SetContent("A test text !");
        System.out.println("The content in Text Shape is :" + myTextShapeObject.GetContent());
        
    }
}

/**
 *  The Class Adapter in this sample 
 */


public class TextShapeClass  extends Text implements Shape {
    public TextShapeClass() {
    }
    public void Draw() {
        System.out.println("Draw a shap ! Impelement Shape interface !");
    }
    public void Border() {
        System.out.println("Set the border of the shap ! Impelement Shape interface !");
    }
    public static void main(String[] args) {
        TextShapeClass myTextShapeClass = new TextShapeClass();
        myTextShapeClass.Draw();
        myTextShapeClass.Border();
        myTextShapeClass.SetContent("A test text !");
        System.out.println("The content in Text Shape is :" + myTextShapeClass.GetContent());
    }
}


[解决办法]
路过,只为分。没考虑其他。

以上谢谢
[解决办法]
在来一个简单的外观模式~

/**
 *  Facade pattern
 */
import java.io.*;

class Wall {
    public Wall() {
        System.out.println("Create a wall !");
    }
}

class Door {
    public Door() {
        System.out.println("Create a door !");
    }
}

class FacadeRoom {
    public void CreateRoom() {
        Wall wall1 = new Wall();
        Wall wall2 = new Wall();
        Wall wall3 = new Wall();
        Wall wall4 = new Wall();
        Door door = new Door();
    }

}

public class Test  {
    public static void main(String[] args) {
        FacadeRoom room = new FacadeRoom();
        room.CreateRoom();
    }
}

[解决办法]
你这个单独怎么写啊。
[解决办法]
散完没
[解决办法]
顶 接分
[解决办法]
单例模式:

//Singleton.java
public class Singleton {

private static Singleton instance;

private Singleton() {
}

public static Singleton GetInstance() {


if (instance == null) {
instance = new Singleton();
}

return instance;
}

}





//main.java
public class main {

/**
 * @param args
 */
public static void main(String[] args) {
// TODO Auto-generated method stub
Singleton s1 = Singleton.GetInstance();
Singleton s2 = Singleton.GetInstance();

if (s1 == s2)
System.out.println("两个对象是相同的实例");

}

}



不对敬请斧正
[解决办法]
//**********结构型模式********** 

//Adapter 
//基本方法有两种,一种是使用引用一种使用继承 
//将不符合标准的接口转成符合标准的接口,接口的修改主要是参数的增减, 
//返回值类型,当然还有方法名 
//感觉这就是封装的另一种表示形式,封装有用方法封装(在方法中调用功能方法), 
//用类封装(先传入功能方法所在的类的对象,通过调用此对象的功能方法) 

//使用引用的形式 
class Adapteea { 
public void kk() {} 


interface Targeta { 
String vv(int i, int k); 


class Adaptera implements Targeta{ 
Adapteea ade; 

public Adaptera(Adapteea ade) { 
this.ade = ade; 


public String vv(int i, int k) { 
//具体的业务方法实现在Adaptee中,这个方法 
//只起到了接口转换的作用 
//调用此方法是通过引用 
ade.kk(); 
return null; 



//使用继承形式的 
class Adapteeb { 
public void kk() {} 


interface Targetb { 
String vv(int i, int k); 


class Adapterb extends Adapteeb implements Targetb { 
public String vv(int i, int k) { 
//调用此方法是通过继承 
kk(); 
return null; 



//Proxy 
interface Subject { 
void request(); 


class realSubject implements Subject { 
public void request() { 
//do the real business 



class Proxy implements Subject { 
Subject subject; 

public Proxy(Subject subject) { 
this.subject = subject; 


public void request() { 
System.out.println("do something"); 

subject.request(); 

System.out.println("do something"); 



//Bridge 
//感觉就是多态的实现 

interface Imp { 
void operation(); 


class Cimp1 implements Imp { 
public void operation() { 
System.out.println("1"); 



class Cimp2 implements Imp { 
public void operation() { 
System.out.println("2"); 



class Invoker { 
Imp imp = new Cimp1(); 

public void invoke() { 
imp.operation(); 



//Composite 

interface Component { 
void operation(); 

void add(Component component); 



void remove(Component component); 


class Leaf implements Component { 
public void operation() { 
System.out.println("an operation"); 


public void add(Component component) { 
throw new UnsupportedOperationException(); 


public void remove(Component component) { 
throw new UnsupportedOperationException(); 



class Composite implements Component { 
List components = new ArrayList(); 

public void operation() { 
Component component = null; 

Iterator it = components.iterator(); 
while (it.hasNext()) { 
//不知道此component对象是leaf还是composite, 
//如果是leaf则直接实现操作,如果是composite则继续递归调用 
component = (Component) it.next(); 
component.operation(); 



public void add(Component component) { 
components.add(component); 


public void remove(Component component) { 
components.remove(component); 



//Decorator 
//对一个类的功能进行扩展时,我可以使用继承,但是不够灵活,所以选用了 
//另外的一种形式,引用与继承都可活得对对象的一定的使用能力,而使用引用将更灵活 
//我们要保证是对原功能的追加而不是修改,否则只能重写方法,或使用新的方法 
//注意concrete的可以直接new出来, 
//而decorator的则需要用一个另外的decorator对象才能生成对象 
//使用对象封装,和公用接口 
//Decorator链上可以有多个元素 

interface Componenta { 
void operation(); 


class ConcreteComponent implements Componenta { 
public void operation() { 
System.out.println("do something"); 



class Decorator implements Componenta { 
private Componenta component; 

public Decorator(Componenta component) { 
this.component = component; 


public void operation() { 
//do something before 

component.operation(); 

//do something after 



//Facade 
//非常实用的一种设计模式,我可以为外部提供感兴趣的接口 

class Obj1 { 
public void ope1() {} 
public void ope2() {} 


class Obj2 { 
public void ope1() {} 
public void ope2() {} 


class Facade { 
//我得到了一个简洁清晰的接口 
public void fdMethod() { 
Obj1 obj1 = new Obj1(); 
Obj2 obj2 = new Obj2(); 

obj1.ope1(); 
obj2.ope2(); 



//Flyweight 
//空


[解决办法]
帮顶

up
[解决办法]
职责链模式:


//ConcreteHandler1.java
public class ConcreteHandler1 extends Handler {
@Override
public void HandleRequest(int request) {
// TODO Auto-generated method stub
if(request>=0&&request<10)
{
System.out.println("处理请求{1}"+this.getClass().getName()+request);

}
else if(Successor!=null)
{


Successor.HandleRequest(request)
;
}
}
}




//ConcreteHandler2.java
public class ConcreteHandler2 extends Handler{

@Override
public void HandleRequest(int request) {
// TODO Auto-generated method stub
if(request>=10&&request<20){
System.out.println("处理请求"+this.getClass().getName()+request);
}
else if(Successor!=null)
{
Successor.HandleRequest(request);
}

}

}



//ConcreteHandler3.java

public class ConcreteHandler3 extends Handler {

@Override
public void HandleRequest(int request) {
// TODO Auto-generated method stub
if(request>=20&&request<30)
{
System.out.println("处理请求"+this.getClass().getName()+request);
}
else if(Successor!=null){
Successor.HandleRequest(request);
}


}}




//Handler.java

public abstract class Handler {
   protected Handler Successor;
   public void SetSuccessor(Handler successor)
   {
   this.Successor=successor;
   }
   public abstract void HandleRequest(int request);

}
/


//main.java

public class Main {

/**
 * @param args
 */
public static void main(String[] args) {
// TODO Auto-generated method stub
Handler h1=new ConcreteHandler1();
Handler h2=new ConcreteHandler2();
Handler h3=new ConcreteHandler3();
h1.SetSuccessor(h2);
h2.SetSuccessor(h3);
int requests[]={2,5,14,22,18,3,27,20};
for(int request:requests)
{
h1.HandleRequest(request);

}

}

}

[解决办法]
代理模式
using System;
using System.Collections.Generic;
using System.Text;

namespace DailiMoshi
{
    class Program
    {
        static void Main(string[] args)
        {
            Ren ren = new Ren();
            ren.Name = "tangtang";
            Daili daili = new Daili(ren);
            daili.Songhua();
            daili.SongJieZhi();
            Console.Read();
        }
    }
    class Ren {

        private string name;

        public string Name
        {
            get { return name; }


            set { name = value; }
        }
    
    }
    interface Songliwu{//追求者的行为
        void Songhua();
        void SongJieZhi();
    
    }
     class Zuiqiuzhe:Songliwu//追求者类
     {
         Ren re;

         public Zuiqiuzhe(Ren ren) {

             this.re = ren;
         }
         #region Songliwu 成员

         public void Songhua()//追求者的行为
         {
             Console.WriteLine(re.Name+"送你花");
         }

         public void SongJieZhi()//追求者的行为
         {
             Console.WriteLine(re.Name + "送你戒指");
         }

         #endregion
     }
    class Daili:Songliwu//代理类
    {
        Zuiqiuzhe zuiqiu;//追求者

        public Daili(Ren ren)
        {
            zuiqiu = new Zuiqiuzhe(ren);//谁让代理
        
        }
        #region Songliwu 成员

        public void Songhua()
        {
            zuiqiu.Songhua();//代理的行为
        }

        public void SongJieZhi()
        {
            zuiqiu.SongJieZhi();//代理的行为
        }

        #endregion
        //总结:代理模式 就是本类属于自己的方法,可以间接的让代理帮我们完成,WebService 我们先把WebServices引入项目中,在项目中就会生成一个类,就是代理,他代理了WebServics的所有方法
    }
    
}

[解决办法]
好贴,你懂的。
[解决办法]
有意思
没想到design patterns 还都有中文名的
[解决办法]
这几天也在看,帮UP
[解决办法]
帮顶+节分 嘿嘿
[解决办法]
一直想自己看,还没机会,帮顶了,接点分,呵呵。


[解决办法]
捧场。。。
[解决办法]
ding............
[解决办法]
帮顶,纯接分,

[解决办法]
顶~~~~~~~~~~~~~~~
[解决办法]
就用过工厂,单例。。。
[解决办法]
该回复于2012-08-28 09:17:14被版主删除
[解决办法]
学习了
[解决办法]
没学设计模式呢 不过有次看斗地主棋牌游戏MFC代码 看到 stdafx.h 里 Managers manager; 感觉这就是总管模式

一个manager掌握全部~
[解决办法]
跟着学习
[解决办法]
精华帖,来看看。
[解决办法]
看看的

热点排行