473,732 Members | 2,214 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.prin tln("RoundPeg insertIntoHole( ) : " + msg); }
}

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

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

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

public class SquarePeg
{
public void insert(String str)
{ System.out.prin tln("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.inser t("Inserting square peg . . .");
PegAdapter adapter = new PegAdapter (roundPeg);
adapter.insert( "Inserting round peg . . .");
}
}

//Tony
Sep 3 '05 #1
0 2706

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

Similar topics

2
2096
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 of the garbage collector to run before the memory is returned to the heap. The first time the GC runs the Finalize method is called, then the second time the memory is actually freed. The problem is that most of the major classes in the .NET...
2
1143
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 main I get this compile error of ambigious vector<MBase*> b; b.push_back(=new MI);
1
3297
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 - defines the domain-specific interface that Client uses. * Client
0
2619
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 understand the book explanation for Target and Client. But I don't understand the book explanation for Adaptee and Adaptor see below. Can somebody explain what the book is trying to say for the Adaptee
5
1024
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) values(@number,@jobno)" With .Parameters .Add("@number", SqlDbType.VarChar, 20, Trim(Me.txtHBLNo.Text)) '.Add("@jobno", SqlDbType.VarChar, 20,
12
2740
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 it defines the language more completely. Great to use.
2
1383
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 which is very similar to this. The guts of the program is ... Dim i As Integer Dim rgx As Regex Dim Pattern As String = "<td class=td1 width=""35%"">(<b>){0,1}(?<variable>(\w| )+)</td>" + _
6
1927
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 for service consumers, at design time. But, I think the cnsumers must completely know all aspects of that service. This sounds not good, and breaks the decoupling rule. So how to understand the role of Service, in a software engineering...
19
1747
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 concepts and terms but I lack practical experience
0
8946
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9307
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9235
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9181
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6735
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.