473,385 Members | 1,320 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Bridge pattern? What is the use?

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++]);
}
}
}
}
Oct 11 '06 #1
12 1958
l'art pour decoupler une abstraction de son execution ;)
http://en.wikipedia.org/wiki/Bridge_pattern

Adrian wrote:
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++]);
}
}
}
}
Oct 11 '06 #2
"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
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?

Oct 11 '06 #3
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...
l'art pour decoupler une abstraction de son execution ;)
http://en.wikipedia.org/wiki/Bridge_pattern
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?
Oct 11 '06 #4
Hi Adrian,

Maybe this link will clear it up more for you:

G.O.F. on Bridge:
http://www.dofactory.com/Patterns/PatternBridge.aspx
I believe you have partially identified the bridge. The part that you didn't acknowledge is the two abstract classes and the
decoupling of the implementation.

The GOF example is much clearer, IMO. Look at the C# code sample.

To equate their sample to your sample:

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

customers.Data = new PrimaryCustomersData();
customers.show();

customers.Data = new SpecialProcessCustomersData();
customers.show();
}
Also, note that show can call multiple methods on the Data object if necessary, so it doesn't have to simply be pass-thru as in
these examples. In that case the concrete CustomerBase implementation acts as a facade as well. Also, concrete CustomerBase
implementations would commonly have different, higher-level methods than the associated Data object.

Its useage might be even clearer if you look at a method that takes a parameter of type, "CustomerBase". In that case the benefit
of both the abstraction and decoupling of implementation is more apparent:

public void ShowCustomerToUser(CustomerBase customer)
{
customer.show();
}

HTH

--
Dave Sexton

"Adrian" <no*@all.accessiblewrote in message news:45********************@dreader2.news.tiscali. nl...
"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
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?

Oct 11 '06 #5
Is using abstract and concrete classes (decoupling)
for hiding the concrete classes from users? If not,
why is it done?

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:O$**************@TK2MSFTNGP02.phx.gbl...
Hi Adrian,

Maybe this link will clear it up more for you:

G.O.F. on Bridge:
http://www.dofactory.com/Patterns/PatternBridge.aspx
I believe you have partially identified the bridge. The part that you
didn't acknowledge is the two abstract classes and the
decoupling of the implementation.

The GOF example is much clearer, IMO. Look at the C# code sample.

To equate their sample to your sample:

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

customers.Data = new PrimaryCustomersData();
customers.show();

customers.Data = new SpecialProcessCustomersData();
customers.show();
}
Also, note that show can call multiple methods on the Data object if
necessary, so it doesn't have to simply be pass-thru as in
these examples. In that case the concrete CustomerBase implementation
acts as a facade as well. Also, concrete CustomerBase
implementations would commonly have different, higher-level methods than
the associated Data object.
>
Its useage might be even clearer if you look at a method that takes a
parameter of type, "CustomerBase". In that case the benefit
of both the abstraction and decoupling of implementation is more apparent:

public void ShowCustomerToUser(CustomerBase customer)
{
customer.show();
}

HTH

--
Dave Sexton

"Adrian" <no*@all.accessiblewrote in message
news:45********************@dreader2.news.tiscali. nl...
"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
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?



Oct 11 '06 #6
Hi Adrian,

Exactly. By using an abstract class you can swap out the implementation in the caller whenever you need to refactor your code and
it enables your code to be dynamic enough when you need to vary implementations at runtime. The consumer of the class doesn't need
to be aware of the implemention, it just needs a reference to the interface (abstract class in this case).

Be aware when using patterns that decouple implemention by using polymorphism that if you see something like the following you
should probably invest your time in finding a more appropriate pattern to meet your needs:

public void ShowCustomerToUser(CustomerBase customer)
{
if (customer.GetType() == typeof(SpecialProcessCustomerData))
{
// we require a special process to occur first, in this case
customer.SpecialProcess();
}

// all customers may be "shown"
customer.show();
}

Hopefully you see the benefit of the bridge pattern and how it could be used to alleviate any need for the explicit Type check
above. The idea is to "abstract" the "ShowCustomerToUser" method from requiring a reference or any knowledge at all of the
implementation of the specified "customer" object.

public class SpecialProcessCustomerData : DataObject
{
public void show()
{
// TODO: special processing
// TODO: show something
}
}

--
Dave Sexton

"Adrian" <no*@all.accessiblewrote in message news:45********************@dreader2.news.tiscali. nl...
Is using abstract and concrete classes (decoupling)
for hiding the concrete classes from users? If not,
why is it done?

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:O$**************@TK2MSFTNGP02.phx.gbl...
>Hi Adrian,

Maybe this link will clear it up more for you:

G.O.F. on Bridge:
http://www.dofactory.com/Patterns/PatternBridge.aspx
I believe you have partially identified the bridge. The part that you
didn't acknowledge is the two abstract classes and the
>decoupling of the implementation.

The GOF example is much clearer, IMO. Look at the C# code sample.

To equate their sample to your sample:

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

customers.Data = new PrimaryCustomersData();
customers.show();

customers.Data = new SpecialProcessCustomersData();
customers.show();
}
Also, note that show can call multiple methods on the Data object if
necessary, so it doesn't have to simply be pass-thru as in
>these examples. In that case the concrete CustomerBase implementation
acts as a facade as well. Also, concrete CustomerBase
>implementations would commonly have different, higher-level methods than
the associated Data object.
>>
Its useage might be even clearer if you look at a method that takes a
parameter of type, "CustomerBase". In that case the benefit
>of both the abstraction and decoupling of implementation is more apparent:

public void ShowCustomerToUser(CustomerBase customer)
{
customer.show();
}

HTH

--
Dave Sexton

"Adrian" <no*@all.accessiblewrote in message
news:45********************@dreader2.news.tiscali. nl...
"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

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?



Oct 11 '06 #7
In case of: / if you do as you suggest:
customers.Data = new PrimaryCustomersData();
customers.show();
customers[] isn't filled
and the appp errors out

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:O$**************@TK2MSFTNGP02.phx.gbl...
Hi Adrian,

Maybe this link will clear it up more for you:

G.O.F. on Bridge:
http://www.dofactory.com/Patterns/PatternBridge.aspx
I believe you have partially identified the bridge. The part that you
didn't acknowledge is the two abstract classes and the
decoupling of the implementation.

The GOF example is much clearer, IMO. Look at the C# code sample.

To equate their sample to your sample:

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

customers.Data = new PrimaryCustomersData();
customers.show();

customers.Data = new SpecialProcessCustomersData();
customers.show();
}
Also, note that show can call multiple methods on the Data object if
necessary, so it doesn't have to simply be pass-thru as in
these examples. In that case the concrete CustomerBase implementation
acts as a facade as well. Also, concrete CustomerBase
implementations would commonly have different, higher-level methods than
the associated Data object.
>
Its useage might be even clearer if you look at a method that takes a
parameter of type, "CustomerBase". In that case the benefit
of both the abstraction and decoupling of implementation is more apparent:

public void ShowCustomerToUser(CustomerBase customer)
{
customer.show();
}

HTH

--
Dave Sexton

"Adrian" <no*@all.accessiblewrote in message
news:45********************@dreader2.news.tiscali. nl...
"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
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?



Oct 11 '06 #8
By the way I did add on another child of DataObject.

"Adrian" <no*@all.accessiblewrote in message
news:45********************@dreader2.news.tiscali. nl...
In case of: / if you do as you suggest:
customers.Data = new PrimaryCustomersData();
customers.show();

customers[] isn't filled
and the appp errors out

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:O$**************@TK2MSFTNGP02.phx.gbl...
Hi Adrian,

Maybe this link will clear it up more for you:

G.O.F. on Bridge:
http://www.dofactory.com/Patterns/PatternBridge.aspx
I believe you have partially identified the bridge. The part that you
didn't acknowledge is the two abstract classes and the
decoupling of the implementation.

The GOF example is much clearer, IMO. Look at the C# code sample.

To equate their sample to your sample:

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

customers.Data = new PrimaryCustomersData();
customers.show();

customers.Data = new SpecialProcessCustomersData();
customers.show();
}
Also, note that show can call multiple methods on the Data object if
necessary, so it doesn't have to simply be pass-thru as in
these examples. In that case the concrete CustomerBase implementation
acts as a facade as well. Also, concrete CustomerBase
implementations would commonly have different, higher-level methods than
the associated Data object.

Its useage might be even clearer if you look at a method that takes a
parameter of type, "CustomerBase". In that case the benefit
of both the abstraction and decoupling of implementation is more
apparent:

public void ShowCustomerToUser(CustomerBase customer)
{
customer.show();
}

HTH

--
Dave Sexton

"Adrian" <no*@all.accessiblewrote in message
news:45********************@dreader2.news.tiscali. nl...
"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
>>
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?
>
>
>


Oct 11 '06 #9
Hi Adrian,

I'm not sure I understand what you mean. The app won't even compile because the PrimaryCustomersData class isn't defined. I was
just trying to illustrate a point: Being able to assign any implementation to the Data property is part of the flexibility provided
by the bridge pattern.

If you tried to compile the application after creating your own PrimaryCustomersData class then it's your implementation that is
failing.

Care to post your code?

--
Dave Sexton

"Adrian" <no*@all.accessiblewrote in message news:45********************@dreader2.news.tiscali. nl...
In case of: / if you do as you suggest:
> customers.Data = new PrimaryCustomersData();
customers.show();

customers[] isn't filled
and the appp errors out

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:O$**************@TK2MSFTNGP02.phx.gbl...
>Hi Adrian,

Maybe this link will clear it up more for you:

G.O.F. on Bridge:
http://www.dofactory.com/Patterns/PatternBridge.aspx
I believe you have partially identified the bridge. The part that you
didn't acknowledge is the two abstract classes and the
>decoupling of the implementation.

The GOF example is much clearer, IMO. Look at the C# code sample.

To equate their sample to your sample:

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

customers.Data = new PrimaryCustomersData();
customers.show();

customers.Data = new SpecialProcessCustomersData();
customers.show();
}
Also, note that show can call multiple methods on the Data object if
necessary, so it doesn't have to simply be pass-thru as in
>these examples. In that case the concrete CustomerBase implementation
acts as a facade as well. Also, concrete CustomerBase
>implementations would commonly have different, higher-level methods than
the associated Data object.
>>
Its useage might be even clearer if you look at a method that takes a
parameter of type, "CustomerBase". In that case the benefit
>of both the abstraction and decoupling of implementation is more apparent:

public void ShowCustomerToUser(CustomerBase customer)
{
customer.show();
}

HTH

--
Dave Sexton

"Adrian" <no*@all.accessiblewrote in message
news:45********************@dreader2.news.tiscali. nl...
"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

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?



Oct 11 '06 #10
Dave, I can see what you are getting at here. How the bridge pattern does a
better job
then polymorphism.

I have successfully implemented your suggestions to bear out the workings of
the example a bit better now.

Your remarks do a good job in explaining the know-why of the bridge pattern.

Unfortunately too often *only* know-how and know-when is explained.

Many thanks,
Adrian. (Nom de plume.)

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:O2**************@TK2MSFTNGP05.phx.gbl...
Hi Adrian,

Exactly. By using an abstract class you can swap out the implementation
in the caller whenever you need to refactor your code and
it enables your code to be dynamic enough when you need to vary
implementations at runtime. The consumer of the class doesn't need
to be aware of the implemention, it just needs a reference to the
interface (abstract class in this case).
>
Be aware when using patterns that decouple implemention by using
polymorphism that if you see something like the following you
should probably invest your time in finding a more appropriate pattern to
meet your needs:
>
public void ShowCustomerToUser(CustomerBase customer)
{
if (customer.GetType() == typeof(SpecialProcessCustomerData))
{
// we require a special process to occur first, in this case
customer.SpecialProcess();
}

// all customers may be "shown"
customer.show();
}

Hopefully you see the benefit of the bridge pattern and how it could be
used to alleviate any need for the explicit Type check
above. The idea is to "abstract" the "ShowCustomerToUser" method from
requiring a reference or any knowledge at all of the
implementation of the specified "customer" object.

public class SpecialProcessCustomerData : DataObject
{
public void show()
{
// TODO: special processing
// TODO: show something
}
}

--
Dave Sexton

"Adrian" <no*@all.accessiblewrote in message
news:45********************@dreader2.news.tiscali. nl...
Is using abstract and concrete classes (decoupling)
for hiding the concrete classes from users? If not,
why is it done?

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:O$**************@TK2MSFTNGP02.phx.gbl...
Hi Adrian,

Maybe this link will clear it up more for you:

G.O.F. on Bridge:
http://www.dofactory.com/Patterns/PatternBridge.aspx
I believe you have partially identified the bridge. The part that you
didn't acknowledge is the two abstract classes and the
decoupling of the implementation.

The GOF example is much clearer, IMO. Look at the C# code sample.

To equate their sample to your sample:

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

customers.Data = new PrimaryCustomersData();
customers.show();

customers.Data = new SpecialProcessCustomersData();
customers.show();
}
Also, note that show can call multiple methods on the Data object if
necessary, so it doesn't have to simply be pass-thru as in
these examples. In that case the concrete CustomerBase implementation
acts as a facade as well. Also, concrete CustomerBase
implementations would commonly have different, higher-level methods
than
the associated Data object.
>
Its useage might be even clearer if you look at a method that takes a
parameter of type, "CustomerBase". In that case the benefit
of both the abstraction and decoupling of implementation is more
apparent:
>
public void ShowCustomerToUser(CustomerBase customer)
{
customer.show();
}

HTH

--
Dave Sexton

"Adrian" <no*@all.accessiblewrote in message
news:45********************@dreader2.news.tiscali. nl...
"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

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?




Oct 11 '06 #11
Dave, please see my other post to you.
Many thanks.

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:eQ*************@TK2MSFTNGP03.phx.gbl...
Hi Adrian,

I'm not sure I understand what you mean. The app won't even compile
because the PrimaryCustomersData class isn't defined. I was
just trying to illustrate a point: Being able to assign any
implementation to the Data property is part of the flexibility provided
by the bridge pattern.

If you tried to compile the application after creating your own
PrimaryCustomersData class then it's your implementation that is
failing.

Care to post your code?

--
Dave Sexton

"Adrian" <no*@all.accessiblewrote in message
news:45********************@dreader2.news.tiscali. nl...
In case of: / if you do as you suggest:
customers.Data = new PrimaryCustomersData();
customers.show();
customers[] isn't filled
and the appp errors out

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:O$**************@TK2MSFTNGP02.phx.gbl...
Hi Adrian,

Maybe this link will clear it up more for you:

G.O.F. on Bridge:
http://www.dofactory.com/Patterns/PatternBridge.aspx
I believe you have partially identified the bridge. The part that you
didn't acknowledge is the two abstract classes and the
decoupling of the implementation.

The GOF example is much clearer, IMO. Look at the C# code sample.

To equate their sample to your sample:

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

customers.Data = new PrimaryCustomersData();
customers.show();

customers.Data = new SpecialProcessCustomersData();
customers.show();
}
Also, note that show can call multiple methods on the Data object if
necessary, so it doesn't have to simply be pass-thru as in
these examples. In that case the concrete CustomerBase implementation
acts as a facade as well. Also, concrete CustomerBase
implementations would commonly have different, higher-level methods
than
the associated Data object.
>
Its useage might be even clearer if you look at a method that takes a
parameter of type, "CustomerBase". In that case the benefit
of both the abstraction and decoupling of implementation is more
apparent:
>
public void ShowCustomerToUser(CustomerBase customer)
{
customer.show();
}

HTH

--
Dave Sexton

"Adrian" <no*@all.accessiblewrote in message
news:45********************@dreader2.news.tiscali. nl...
"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

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?




Oct 11 '06 #12
Hi Adrian,

Glad I could help.
Unfortunately too often *only* know-how and know-when is explained.
I agree, but books and in-depth articles usually fill in the blanks nicely.

--
Dave Sexton

"Adrian" <no*@all.accessiblewrote in message news:45********************@dreader2.news.tiscali. nl...
Dave, I can see what you are getting at here. How the bridge pattern does a
better job
then polymorphism.

I have successfully implemented your suggestions to bear out the workings of
the example a bit better now.

Your remarks do a good job in explaining the know-why of the bridge pattern.

Unfortunately too often *only* know-how and know-when is explained.

Many thanks,
Adrian. (Nom de plume.)

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:O2**************@TK2MSFTNGP05.phx.gbl...
>Hi Adrian,

Exactly. By using an abstract class you can swap out the implementation
in the caller whenever you need to refactor your code and
>it enables your code to be dynamic enough when you need to vary
implementations at runtime. The consumer of the class doesn't need
>to be aware of the implemention, it just needs a reference to the
interface (abstract class in this case).
>>
Be aware when using patterns that decouple implemention by using
polymorphism that if you see something like the following you
>should probably invest your time in finding a more appropriate pattern to
meet your needs:
>>
public void ShowCustomerToUser(CustomerBase customer)
{
if (customer.GetType() == typeof(SpecialProcessCustomerData))
{
// we require a special process to occur first, in this case
customer.SpecialProcess();
}

// all customers may be "shown"
customer.show();
}

Hopefully you see the benefit of the bridge pattern and how it could be
used to alleviate any need for the explicit Type check
>above. The idea is to "abstract" the "ShowCustomerToUser" method from
requiring a reference or any knowledge at all of the
>implementation of the specified "customer" object.

public class SpecialProcessCustomerData : DataObject
{
public void show()
{
// TODO: special processing
// TODO: show something
}
}

--
Dave Sexton

"Adrian" <no*@all.accessiblewrote in message
news:45********************@dreader2.news.tiscali. nl...
Is using abstract and concrete classes (decoupling)
for hiding the concrete classes from users? If not,
why is it done?

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:O$**************@TK2MSFTNGP02.phx.gbl...
Hi Adrian,

Maybe this link will clear it up more for you:

G.O.F. on Bridge:
http://www.dofactory.com/Patterns/PatternBridge.aspx
I believe you have partially identified the bridge. The part that you
didn't acknowledge is the two abstract classes and the
decoupling of the implementation.

The GOF example is much clearer, IMO. Look at the C# code sample.

To equate their sample to your sample:

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

customers.Data = new PrimaryCustomersData();
customers.show();

customers.Data = new SpecialProcessCustomersData();
customers.show();
}
Also, note that show can call multiple methods on the Data object if
necessary, so it doesn't have to simply be pass-thru as in
these examples. In that case the concrete CustomerBase implementation
acts as a facade as well. Also, concrete CustomerBase
implementations would commonly have different, higher-level methods
than
the associated Data object.

Its useage might be even clearer if you look at a method that takes a
parameter of type, "CustomerBase". In that case the benefit
of both the abstraction and decoupling of implementation is more
apparent:
>>
public void ShowCustomerToUser(CustomerBase customer)
{
customer.show();
}

HTH

--
Dave Sexton

"Adrian" <no*@all.accessiblewrote in message
news:45********************@dreader2.news.tiscali. nl...
"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

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?





Oct 11 '06 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Steven M. Scotten | last post by:
Hi-- I seem to have the PHP Java Bridge (2.0.5 built from tarball) working with PHP 5.0.3 (also built from tarball) on my Fedora Core 1 server with Apache 2.0.50 and I'm pretty excited about it...
2
by: Debajit Adhikary | last post by:
I'm still pretty new to design patterns... I was wondering, is there any difference between the Bridge Pattern and Herb Sutter's Pimpl Idiom? Both delegate responsibility to an implementation...
5
by: Lorn | last post by:
I'm undertaking wriitng a bridge application between a remote data server API and multiple utility applications which pull and send data to the API. The reason for a bridge is that the data server...
0
by: Tony Johansson | last post by:
Hello Experts! Some information. In a more general form is the handle body principles called the bridge design pattern. In the handle class you have a delegate that points to an pure abstract...
4
by: Izak van Langevelde | last post by:
Shocks. Today I came to learn that Suns jdbc-odbc bridge driver isn't meant for serious purposes; it's experimental. I already knew it isn't thread safe, but didn't think of this as problematic for...
0
by: sneha29 | last post by:
Hi, I am trying to write a bridge similar to Python- Uno bridge. I have read from these links about the PyUNO bridge. http://udk.openoffice.org/python/python-bridge.html But I haven't found...
0
by: ghost_of_rooney | last post by:
Maybe my example isn't a good candidate for Bridge, or maybe I'm applying Bridge incorrectly, but I don't see the benefit of the pattern here. If I eliminated the Bridge and extended the shape...
2
by: Simon Woods | last post by:
Hi I'm just working through (and learning) the standard GoF Design Pattern and the example of the Bridge pattern on http://www.dofactory.com/Patterns/PatternBridge.aspx#_self2 I notice at the...
1
pbmods
by: pbmods | last post by:
Heya. I just installed PHP-Java-Bridge on my system, but I'm having a hard time getting it to stop crashing Apache. When I activate the 'Java.so' module in php.ini, I get the following error in...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.