473,395 Members | 1,474 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,395 software developers and data experts.

useless design pattern

Hello,

I have come across a class whose structure looks like this:

class Foo {

public:

// ...

private:

FooMarker *fooMarker;

};

class FooMarker {

public:

inline FooMarker(): myStr(0) { }

private:

inline FooMarker(const char *str): myStr(str) { }

friend class Foo;

const char *myStr;

};

----------------------------------------------------

Why not just:

class Foo {

public:

// ...

private:

const char *fooMarker;

};

Seems quite useless to me. Any suggestions?
I would be surprised if such a class were created
just for the sake of adding a class. There must be
some better reason for this.

Thanks,

JG

Oct 30 '06 #1
3 1334
John Goche wrote:
Hello,

I have come across a class whose structure looks like this:

class Foo {

public:

// ...

private:

FooMarker *fooMarker;

};

class FooMarker {

public:

inline FooMarker(): myStr(0) { }

private:

inline FooMarker(const char *str): myStr(str) { }

friend class Foo;

const char *myStr;

};

----------------------------------------------------

Why not just:

class Foo {

public:

// ...

private:

const char *fooMarker;

};

Seems quite useless to me. Any suggestions?
I would be surprised if such a class were created
just for the sake of adding a class. There must be
some better reason for this.
There must be. And since you're not showing how the member of
'Foo' is used (you gave "// ..." there), I can't tell without
making too many wild assumptions. So, I'll refrain.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Oct 30 '06 #2
"John Goche" <jo*******@gmail.comwrote:
Hello,

I have come across a class whose structure looks like this:

class Foo {

public:

// ...

private:

FooMarker *fooMarker;

};

class FooMarker {

public:

inline FooMarker(): myStr(0) { }

private:

inline FooMarker(const char *str): myStr(str) { }

friend class Foo;

const char *myStr;

};

----------------------------------------------------

Why not just:

class Foo {

public:

// ...

private:

const char *fooMarker;

};

Seems quite useless to me. Any suggestions?
I would be surprised if such a class were created
just for the sake of adding a class. There must be
some better reason for this.
Is "FooMarker" ever mentioned in the public interface of Foo?

--
To send me email, put "sheltie" in the subject.
Oct 30 '06 #3
Daniel T. wrote:
Is "FooMarker" ever mentioned in the public interface of Foo?
Indeed, FooMarker is used in the public interface of Foo. So the
only reason to have this class is to hide implementation details
from the user of the Foo class. There are Foo member functions
to set a FooMarker from a passed in value as well as functions
to do some processing and retrieve corresponding values of
FooMarker. These retrieved values can then be stored on
the user side and possibly passed in to the Foo instance
by the user of the class.

So yes, it is clear that encapsulation in Foo's public
interface is the reason.

Regards,

JG

Oct 30 '06 #4

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

Similar topics

3
by: Omer van Kloeten | last post by:
The Top Level Design: The class Base is a factory class with a twist. It uses the Assembly/Type classes to extract all types that inherit from it and add them to the list of types that inherit...
11
by: FluffyCat | last post by:
In Febraury - April of 2002 I put together in Java examples of all 23 of the classic "Gang Of Four" design patterns for my website. Partly I wanted to get a better understanding of those patterns....
1
by: Nick | last post by:
I have read a few months ago about a policy design pattern but can find nothing on it now. Does this design pattern exist and if so could someone explain what it is or links to a description. ...
12
by: FluffyCat | last post by:
New on November 28, 2005 for www.FluffyCat.com PHP 5 Design Pattern Examples - the Visitor Pattern. In the Visitor pattern, one class calls a function in another class and passes an instance of...
4
by: FluffyCat | last post by:
New on November 29, 2005 for www.FluffyCat.com PHP 5 Design Pattern Examples - the Command Pattern. Since you all enjoyed the Visitor Pattern so much yesterday, today I have the Command Pattern...
6
by: pitachu | last post by:
Hi, I'm not an expect in .NET, so would anyone know an answer a design pattern for the following? There are many customers that require minor customizations to the program I will be...
4
by: Guch Wu | last post by:
I want to design an image processing class as follow: class Image { Image Data; General Image Operations; read(filename, File_Type); write(filename, File_Type); };
22
by: Krivenok Dmitry | last post by:
Hello All! I am trying to implement my own Design Patterns Library. I have read the following documentation about Observer Pattern: 1) Design Patterns by GoF Classic description of Observer....
6
by: perhapscwk | last post by:
.... ... ... Both of the procedures have repeating sections of code: sending an e-mail and adding a log entry. Task: *1.Select a design pattern (substantiate your choice) that would allow...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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
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
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...

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.