473,406 Members | 2,867 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,406 software developers and data experts.

A question about understand some text for the adaptor pattern

Hello!

Below is a small program using the adaptor pattern.
We have four classes these are: PegAdapter, RoundPeg, SquarePeg
and a class TestPegs acting like a client

In class PegAdapter has some text just above the class header saying
"Its adapts a RoundPeg to a SquarePeg".

In the class that acts as a client which isTestPegs
Just above this class definition of this TestPegs we have some text here
saying
"The solution: create an adapter that adapts a square peg to a round peg!"

Now to my question: It's all about understand the meaning of these two rows?
"Its adapts a RoundPeg to a SquarePeg".
"The solution: create an adapter that adapts a square peg to a round peg!"
The first row is some kind of documentation for class PegAdapter and
the second row is some kind of documentation for class isTestPegs

How can they say in the first row that Its adapts a RoundPeg to a SquarePeg
and in the second row say adapts a square peg to a round peg.
Why is it different?
The row "adapts a RoundPeg to a SquarePeg" is the other way around compared
to row
"adapts a square peg to a round peg"

What is it that decide whether it should be "adapts a RoundPeg to a
SquarePeg" or
"adapts a square peg to a round peg"
public class RoundPeg
{
public void insertIntoHole(String msg)
{ System.out.println("RoundPeg insertIntoHole() : " + msg); }
}

/* Its adapts a RoundPeg to a SquarePeg */
public class PegAdapter extends SquarePeg
{
private RoundPeg roundPeg;

public PegAdapter(RoundPeg peg)
{ this.roundPeg = peg; }

public void insert(String str)
{ roundPeg.insertIntoHole(str); }
}

public class SquarePeg
{
public void insert(String str)
{ System.out.println("SquarePeg insert() : " + str); }
}
// Now we'd like to do an insert using the round peg.
// But this client only understand the insert()
// method of pegs, not a insertIntoHole() mothod.
// The solution: create an adapter that adapts
// a square peg to a round peg!
public class TestPegs
{
public static void main(String args[] )
{
RoundPeg roundPeg = new RoundPeg ();
SquarePeg squarePeg = new SquarePeg ();
squarePeg.insert("Inserting square peg . . .");
PegAdapter adapter = new PegAdapter (roundPeg);
adapter.insert("Inserting round peg . . .");
}
}

//Tony
Sep 3 '05 #1
0 2687

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

Similar topics

2
by: Barry Anderberg | last post by:
I've been doing some reading about Finalize and garbage collection. I've learned that finalizing should be avoided because objects that have a finalize method require 2 (possibly more) itterations...
2
by: Tony Johansson | last post by:
Hello Experts! I reading a book called programming with design pattern revealed by Tomasz Muldner and here I read something that I don't understand completely. When I have these two lines in...
1
by: Tony Johansson | last post by:
Hello! I'm reading about design pattern adaptor in the GOF book and there is something that sounds strange. When you use the adaptor design pattern you have these participants. *Target -...
0
by: Tony Johansson | last post by:
Hello! I'm reading about design pattern adaptor in the GOF book and there is something that sounds strange. The text below each participant is the book explanation for each participant. I...
5
by: Agnes | last post by:
I want to insert a record into a tables by using dataadaptor With cmdSeaExBL .Connection = conSea.GetDbConnection("SEA") .CommandText = "INSERT dbo.billladingheader(number,jobno)...
12
by: Michael S | last post by:
Why do people spend so much time writing complex generic types? for fun? to learn? for use? I think of generics like I do about operator overloading. Great to have as a language-feature, as...
2
by: eBob.com | last post by:
I am using regular expressions and a particular feature called "capture" (I think) to suck some information out of some html. I could have never come up with this myself but Balena has an example...
6
by: dotNeter | last post by:
The services, talked here, are things used in IServiceContainer, IServiceProvider, etc. In my opinion, everything can be a service, and a service is generally used for providing specific features...
19
by: adriancico | last post by:
Hi I am working on a python app, an outliner(a window with a TreeCtrl on the left to select a document, and a RichTextBox at the right to edit the current doc). I am familiarized with OOP...
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
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.