Solved

What pattern is this

Posted on 2010-09-05
3
405 Views
Last Modified: 2012-06-27
Hi,

I saw that in boost::asio.
Maybe someone knows name of this pattern and why/when should i use it or why not.
Its remainds me pimpl idiom.
Pattern looks like this

 
template <typename ServiceName>
class basic_service
{
  typedef ServiceName ImplType
public:
     Init()
     {
        impl_.Init();
     }
private:
    ImplType impl_
};

From what i see. I could pass different types in template argument: 
basic_service<Service1> aaa
basic_service<Service2> bbb

Open in new window

0
Comment
Question by:lavitz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 400 total points
ID: 33608791
>>  From what i see. I could pass different types in template argument:

Yes you are correct, you can pass other types in this manner. What you are looking at is a template class. A template class is one in which you write a common set of logic once and you have the ability to reuse that logic by passing different types into the template parameter. Think of template classes in the same way you were taught classes--but instead of creating a blueprint that will be used to recreate objects of the same type, you are creating a blueprint to recreate logic for different types. Templates allow you to write logic once and reuse that same logic on multiple types of classes. Other languages, such as C# and Java, refer to this style as Generics.

I believe C++ also has the concept of templated functions--where only a single function is templated, not an entire class.
0
 
LVL 22

Assisted Solution

by:ambience
ambience earned 100 total points
ID: 33610185
I think it's called proxy class pattern, also famously known as pimpl pattern in c++ jargon.The basic_service wrapper will proxy calls to the implementation and hence a proxy class.
0
 
LVL 1

Expert Comment

by:XMarshall10
ID: 33610533
I agree that this is an pimpl pattern.

The code: ImplType impl_
  is a forward declaration of an opaque pointer, details of which is implemented in the implementation file (generally the corresponding CPP file).

In C++ jargon, this is also known as Compiler firewall.

-XM
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question