桥模式?有什么用? [英] Bridge pattern? What is the use?

查看:53
本文介绍了桥模式?有什么用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码来自一个例子。

所有噪音在示例中被抛出。

这应该是根据桥梁

模式。代码中的内容(哪一行)

表示桥接模式(根据桥接模式使此代码

),

和使用

桥模式有什么好处?似乎是艺术艺术艺术。对我来说。


Adrian


使用System.Collections;


命名空间trial_seven

{

class Class1

{

[STAThread]

static void Main(string [ ] args)

{

客户客户=新客户(芝加哥);

customers.Data = new CustomersData();

customers.show();

customers.show();

}


类CustomersBase

{

私有DataObject dataObject;

受保护的字符串组;

public CustomersBase(string group)

{

this.group = group;

}


公共DataObject数据

{

set

{

dataObject = value;

}

得到

{

返回dataObject;

}

}


public virtual void show()

{

dataObject.ShowRecord();

}

}


类客户:CustomersBase

{

公众客户(字符串组):base(group)

{< br $>
}

}


抽象类DataObject

{

public abstract void ShowRecord();

}


class CustomersData:DataObject

{

private ArrayList customers = new ArrayList();

private static int current = 0;


public CustomersData()

{

customers.Add(" Jim Jones");

customers.Add(" Frank Rapper");

}

public override void ShowRecord()

{

Console.WriteLine(customers [current ++]);

}

}

}

}

The code below was taken from an example.
All the "noise" in the example was thrown out.
This is supposedly according to the bridge
pattern. What in the code (which lines)
represent the bridge pattern (make this code
to be according to the bridge pattern),
and what is the advantage of employing the
bridge pattern? It seems "l''art pour l''art" to me.

Adrian

using System.Collections;

namespace trial_seven
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
Customers customers = new Customers("Chicago");
customers.Data = new CustomersData();
customers.show();
customers.show();
}

class CustomersBase
{
private DataObject dataObject;
protected string group;
public CustomersBase(string group)
{
this.group = group;
}

public DataObject Data
{
set
{
dataObject = value;
}
get
{
return dataObject;
}
}

public virtual void show()
{
dataObject.ShowRecord();
}
}

class Customers:CustomersBase
{
public Customers (string group):base(group)
{
}
}

abstract class DataObject
{
public abstract void ShowRecord();
}

class CustomersData:DataObject
{
private ArrayList customers = new ArrayList();
private static int current = 0;

public CustomersData()
{
customers.Add("Jim Jones");
customers.Add("Frank Rapper");
}
public override void ShowRecord()
{
Console.WriteLine(customers[current++]);
}
}
}
}

推荐答案

l''art pour decoupler une abstraction de son执行;)
http://en.wikipedia.org/wiki / B ridge_pattern


Adrian写道:
l''art pour decoupler une abstraction de son execution ;)
http://en.wikipedia.org/wiki/Bridge_pattern

Adrian wrote:

下面的代码来自一个例子。

所有噪音在示例中被抛出。

这应该是根据桥梁

模式。代码中的内容(哪一行)

表示桥接模式(根据桥接模式使此代码

),

和使用

桥模式有什么好处?似乎是艺术艺术艺术。对我来说。


Adrian


使用System.Collections;


命名空间trial_seven

{

class Class1

{

[STAThread]

static void Main(string [ ] args)

{

客户客户=新客户(芝加哥);

customers.Data = new CustomersData();

customers.show();

customers.show();

}


类CustomersBase

{

私有DataObject dataObject;

受保护的字符串组;

public CustomersBase(string group)

{

this.group = group;

}


公共DataObject数据

{

set

{

dataObject = value;

}

得到

{

返回dataObject;

}

}


公共虚拟空洞秀()

{

dataObject.ShowRecord();

}

}

类客户:CustomersBase

{

公众客户(字符串组):基数(组)

{

}

}


抽象类DataObject

{

public abstract void ShowRecord ();

}


类CustomersData:DataObject

{

private ArrayList customers = new ArrayList();

private static int current = 0;


public CustomersData()

{

customers.Add(" Jim Jones");

customers.Add(" Frank Rapper");

}

public覆盖void ShowRecord()

{

Console.WriteLine(customers [current ++]);

}

}

}

}
The code below was taken from an example.
All the "noise" in the example was thrown out.
This is supposedly according to the bridge
pattern. What in the code (which lines)
represent the bridge pattern (make this code
to be according to the bridge pattern),
and what is the advantage of employing the
bridge pattern? It seems "l''art pour l''art" to me.

Adrian

using System.Collections;

namespace trial_seven
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
Customers customers = new Customers("Chicago");
customers.Data = new CustomersData();
customers.show();
customers.show();
}

class CustomersBase
{
private DataObject dataObject;
protected string group;
public CustomersBase(string group)
{
this.group = group;
}

public DataObject Data
{
set
{
dataObject = value;
}
get
{
return dataObject;
}
}

public virtual void show()
{
dataObject.ShowRecord();
}
}

class Customers:CustomersBase
{
public Customers (string group):base(group)
{
}
}

abstract class DataObject
{
public abstract void ShowRecord();
}

class CustomersData:DataObject
{
private ArrayList customers = new ArrayList();
private static int current = 0;

public CustomersData()
{
customers.Add("Jim Jones");
customers.Add("Frank Rapper");
}
public override void ShowRecord()
{
Console.WriteLine(customers[current++]);
}
}
}
}


" Chris Fulstow" < ch ********** @ hotmail.comwrote in message

news:11 ******************** **@b28g2000cwb.googlegr oups.com ...
"Chris Fulstow" <ch**********@hotmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...

l''art pour decoupler une abstraction de son execution;)
http://en.wikipedia.org/wiki/Bridge_pattern



是的,这是我得到它的地方:(


" decoupler une abstraction de son execution"

这种情况​​正在发生在我的感知中两次,

但是这似乎并不具体代表

代码声称代表什么,

即a我可以用图像显示,在main中调用

,然后再调用ShowRecord,以

为桥梁。但是有什么用呢

这样做?混淆或三层东西?

Yes that is where I got it from :(

"decoupler une abstraction de son execution"
That is happening twice in my perception,
but that doesn''t seem to be specific for
what the code is purporting to represent,
namely a bridge. I could image show, called
in main, and, in turn, calling ShowRecord, to
be the bridge. But what is so useful about
doing that? Obfuscation or 3-tier stuff?


不是最容易理解的模式,但是这篇文章

解释得非常好:
http ://www.codeproject.com/gen/design/bridge.asp


Adrian写道:
Not the easiest pattern to get your head around, but this article
explains it pretty well:
http://www.codeproject.com/gen/design/bridge.asp

Adrian wrote:

Chris Fulstow < ch ********** @ hotmail.comwrote in message

news:11 ******************** **@b28g2000cwb.googlegr oups.com ...
"Chris Fulstow" <ch**********@hotmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...

l''art pour decoupler une abstraction de son execution;)
http://en.wikipedia.org/wiki/Bridge_pattern



是的,这是我得到它的地方:(


" decoupler une abstraction de son execution"

这在我的认知中发生了两次,

但这似乎并不具体代表

代码声称代表什么,

即桥梁。我可以图像显示,主要叫做
,反过来调用ShowRecord,以

为桥梁。但是对于

有什么用处这样做?混淆或三层东西?

Yes that is where I got it from :(

"decoupler une abstraction de son execution"
That is happening twice in my perception,
but that doesn''t seem to be specific for
what the code is purporting to represent,
namely a bridge. I could image show, called
in main, and, in turn, calling ShowRecord, to
be the bridge. But what is so useful about
doing that? Obfuscation or 3-tier stuff?


这篇关于桥模式?有什么用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆