Tutorials to .com

Tutorials to .com » Software » C » C + + design patterns of the Adapter

C + + design patterns of the Adapter

Print View , by: iSee ,Total views: 34 ,Word Count: 5826 ,Date: Wed, 26 Aug 2009 Time: 4:08 PM

A functional

Will be a class interface into another interface clients want to address the mismatch between the two existing interface problems. Adapter pattern makes the original and not because of incompatible interfaces to work together in those classes can work together.

Second, the structure diagram

(1) class adapter

(2) object adapter

Third, to achieve

Like many other models, learning design Patterns focus on the idea of learning for each model, rather than rigidly adhere to its plan and the achievement of a specific structure. Because the model is flexible, its implementation can be ever-changing, only the so-called original aim. In the STL in the extensive use of the Adapter pattern, like function adapter, iterator adpter, they said here the structure of the adapter are not the same, but the idea is the same. Hou Jie, a specific introduction to the site can be found on the articles, he speaks very good.

4, sample code

(1) class adapter

namespace DesignPattern_Adapter
(
/ / Class Adaptee
class Adaptee
(
public:
void SpecialRequest () ()
);

/ / Class Target
class Target
(
public:
virtual void Request () = 0;
);

/ / Class Adapter
class Adapter: public Target, private Adaptee
(
public:
virtual void Request () (SpecialRequest ();)
);
)

Client-side code:
(
using namespace DesignPattern_Adapter;
Target * p = new Adapter ();
p-> Request (); / / actually calls are Adaptee:: SpecialRequest ()
)

(2) object adapter namespace DesignPattern_Adapter

(
/ / Class Adaptee
class Adaptee
(
public:
void SpecialRequest () ()
);

/ / Class Target
class Target
(
public:
virtual void Request () = 0;
);

/ / Class Adapter
class Adapter: public Target
(
public:
virtual void Request () (_adaptee.SpecialRequest ();)
private:
Adaptee _adaptee;
);
)

Client-side code:
(
using namespace DesignPattern_Adapter;
Target * p = new Adapter ();
p-> Request (); / / actually calls are Adaptee:: SpecialRequest ()
)

6, examples

(1) STL in the Class Adapter

STL in the Adapter Class include: a.stack (corresponding to adaptee is deque). b.queue (corresponding adaptee is deque). c.priority_queue (corresponding adaptee a vector). The following is from the vc of <stack> copy out of the stack class definition:

template class _Container = deque <_Ty>>
class stack
(/ / LIFO queue implemented with a container
public:
typedef _Container container_type;
typedef typename _Container:: value_type value_type;
typedef typename _Container:: size_type size_type;

stack ()
: c ()
(/ / Construct with empty container
)

explicit stack (const _Container & _Cont)
: C++ (_Cont)
(/ / Construct by copying specified container
)

bool empty () const
(/ / Test if stack is empty
return (c.empty ());
)

size_type size () const
(/ / Test length of stack
return (c.size ());
)

value_type & top ()
(/ / Return last element of mutable stack
return (c.back ());
)

const value_type & top () const
(/ / Return last element of nonmutable stack
return (c.back ());
)

void push (const value_type & _Val)
(/ / Insert element at end
c.push_back (_Val);
)

void pop ()
(/ / Erase last element
c.pop_back ();
)

bool _Eq (const stack <_Ty, _Container> & _Right) const
(/ / Test for stack equality
return (c == _Right.c);
)

bool _Lt (const stack <_Ty, _Container> & _Right) const
(/ / Test if this <_Right for stacks
return (c <_Right.c);
)

protected:
_Container C; / / the underlying container
);

The key is that _Container c, stack all of the operations are transferred to the c to deal with. (This is in fact previously mentioned "object adapter", pay attention in class adapter and the STL mentioned above is not fully consistent with the concept of class adapter)
stack is very simple to use, as follows:

(
int ia [] = (1,3,2,4);
deque id (ia, ia +4);
stack is (id);
)

(2) recently read an article "Generic <Programming>: simplify the exception-safe code", the original from http://www.cuj.com/experts/1812/alexandr.htm?topic=experts, from the Chinese translation of "C + + View No. 5. " The article is absolutely first class, the authors also used the code given in the Adaptor pattern, there is a certain representation. I will generalize their problems, to generalize the following example:

Question: Suppose there are several existing classes, they have certain common behavior, but they are independent of each other (no common base class). Such as:

class T1
(
public:
void Proc () ()
);

class T2
(
public:
void Proc () ()
);

/ / ...

   A unified approach to how to call these acts?

Solution 1: I am naturally be thought that using templates, such as:

template <class T>
void Test (T t)
(
t.Proc ();
)

Indeed, good, but this only applies to the simplest case, sometimes the situation is very complicated, such as we are unable to type into the template parameters!

Solution 2: difficulty stems from these classes with no common base class, so we create a base class, then Adapt.

/ / Class IAdaptor, an abstract base class
class IAdaptor
(
public:
virtual void Proc () = 0;
);
/ / Class Adaptor
template <class T>
class Adaptor: public IAdaptor, private T / / implementation inheritance
(
public:
virtual void Proc () (T:: Proc ();)
);
/ / Call the function in a uniform manner Proc, without concern for a T1, T2, or any other type
void Test (const std:: auto_ptr & Sp)
(
sp-> Proc ();
)
Client-side code:
Test (std:: auto_ptr (new Adaptor ));
Test (std:: auto_ptr (new Adaptor ));

On the cases of very simple methods used in a template function can be well resolved. The following is a slightly more complex example, according to parameter type to create the appropriate object:

class T1
(
public:
T1 (int) (/*...*/)
void Proc () (/*...*/)
);

class T2
(
public:
T2 (char) (/*...*/)
void Proc () (/*...*/)
);

/ / Class IAdaptor, an abstract base class
class IAdaptor
(
public:
virtual void Proc () = 0;
);

/ / Class Adaptor
template
class Adaptor: public IAdaptor, private T / / implementation inheritance
(
public:
Adaptor (int n): T (n) ()
Adaptor (char c): T (c) ()
virtual void Proc () (T:: Proc ();)
);

class Test
(
public:
Test (int n): sp (new Adaptor (n)) ()
Test (char c): sp (new Adaptor (c)) ()

void Proc () (sp-> Proc ();)
private:
std:: auto_ptr sp;
);

Client-side code:
Test t1 (10);
t1.Proc ();

Test t2 ( 'c');
t2.Proc ();

The above is a sample rather than an instance, you may be more willing to look at its actual use. Author wrote the code to download, enjoy some good bar.


C + + Design Patterns Abstract Factory
2002-07-23 · · · · COM camp

1, functional <BR> to provide a range of related or dependent objects to create an interface, but without specifying their concrete classes.

Second, the structure diagram

Schematic diagram of the basic class factory is as follows:

In practice, the class factory pattern can be expanded to a very complicated situation, as shown below:

Third, advantages and disadvantages

Advantages: (1) package creation process. Customers do not know how the class factory to create a class instance, the class factory closed down all the details of creation. The creation of such a choice of different ways to increase flexibility. (2) to the client and the specific type isolation, improve their reusability.
Disadvantages: Factory class hierarchy and specific class hierarchy is usually parallel (ie, one to one). To add a concrete class, generally have a corresponding increase in a factory class, an increase of system complexity.

Fourth, to achieve

(1) Abstract Factory classes are often a collection of a set of Factory Method. Personally believe that with the Factory Method pattern there is no essential difference.

(2) usually the factory as a single piece.

5, sample code

namespace DesignPattern_AbstractFactory

(

class AbstractProductA (); / / Product A

class ProductA1: public AbstractProductA ();

class ProductA2: public AbstractProductA ();

class AbstractProductB (); / / Product B
class ProductB1: public AbstractProductB ();
class ProductB2: public AbstractProductB ();
class AbstractFactory
(
public:
virtual AbstractProductA * CreateProductA () = 0; / / Create ProductA
virtual AbstractProductB * CreateProductB () = 0; / / Create ProductB
);
class ConcreteFactory1: public AbstractFactory
(
public:
virtual AbstractProductA * CreateProductA () (return new ProductA1 ();)
virtual AbstractProductB * CreateProductB () (return new ProductB1 ();)
static ConcreteFactory1 * Instance () (static ConcreteFactory1 instance; return & instance;)
protected:
ConcreteFactory1 () ()
private:
ConcreteFactory1 (const ConcreteFactory1 &);
ConcreteFactory1 & operator = (const ConcreteFactory1 &);
);
class ConcreteFactory2: public AbstractFactory
(
public:
virtual AbstractProductA * CreateProductA () (return new ProductA2 ();)
virtual AbstractProductB * CreateProductB () (return new ProductB2 ();)
static ConcreteFactory2 * Instance () (static ConcreteFactory2 instance; return & instance;)
protected:
ConcreteFactory2 () ()
private:
ConcreteFactory2 (const ConcreteFactory2 &);
ConcreteFactory2 & operator = (const ConcreteFactory2 &);
);
)

Client-side code:

(
using namespace DesignPattern_AbstractFactory;
/ / First create a method of

AbstractFactory * pFactory = ConcreteFactory1:: Instance ();
AbstractProductA * pProductA = pFactory-> CreateProductA ();
AbstractProductB * pProductB = pFactory-> CreateProductB ();

/ / The second way to create pFactory = ConcreteFactory2:: Instance ();
pProductA = pFactory-> CreateProductA ();
pProductB = pFactory-> CreateProductB ();
)

6, examples

The earliest knowledge of the concept of class factory in COM, but at that time did not think it is so important as a model in many other models can be used in class-plant system. COM can not directly create the component, this is a feature by COM decision: that customers do not know that you want to create a component class name.


C + + Design Patterns Singleton
2002-07-26 · · · · COM camp

A functional

To ensure only one instance of a class.

Second, the structure diagram




Third, advantages and disadvantages

Singleton pattern is used as "global variable" alternatives emerge. Therefore, it has the characteristics of the global variables: global can be seen throughout the entire application life cycle, it also has global variables do not have the properties: the same type of object instance may have only one.

Fourth, to achieve

Textbook Singleton defined as follows:

class Singleton
(
public:
static Singleton * Instance ();
protected:
Singleton () ()
private:
static Singleton * _instance;
Singleton (const Singleton &);
Singleton & operator = (const Singleton &);
);

Singleton * Singleton:: _instance = NULL;

Singleton * Singleton:: Instance ()
(
(_instance == NULL)? _instance = new Singleton (): 0; / / lazy initialization
return _instance;
)

(1) because the return is a pointer, in order to prevent the user calls delete function, you can put static Singleton * _instance; change in the Instance () is defined in static Singleton _instance. This is clearly more secure, but also has a lazy initialization properties (ie, the first visit when created).

(2) Suppose you want to subclass derived from the Singleton, but also need to subclass the same nature, not only can create only one instance. I think this is difficult to do. The basic reason is Instance () function is not virtual functions, does not have multi-state in nature. One common way is to Instance () function is moved to the sub-category, then can only use static Singleton * _instance, rather than using static Singleton _instance, and unless _instance have to move sub-category, regardless of how to do both is not elegant. Another method is to use the template. The specific method used, only trade-offs based on the actual situation.

5, sample code

(1) No sub-class of

namespace DesignPattern_Singleton
(

class Singleton
(
public:
static Singleton * Instance () (static Singleton _instance; return & _instance;)
protected:
Singleton () ()
private:
Singleton (const Singleton &);
Singleton & operator = (const Singleton &);
);
)

Client-side code:
(
using namespace DesignPattern_Singleton;
Singleton * p = Singleton:: Instance ();
......
)

(2) sub-class of

Method 1:
namespace DesignPattern_Singleton
(
/ / Class Singleton
class Singleton
(
protected:
Singleton () ()
static Singleton * _instance;
private:
Singleton (const Singleton &);
Singleton & operator = (const Singleton &);
);
Singleton * Singleton:: _instance = NULL;

/ / Class ConcreteSingleton
class ConcreteSingleton: public Singleton
(
public:
static Singleton * Instance ();
protected:
ConcreteSingleton () ()
);

Singleton * ConcreteSingleton:: Instance ()
(
(_instance == NULL)? _instance = new ConcreteSingleton (): 0;
return _instance;
)
)

Client-side code:
(
using namespace DesignPattern_Singleton;
Singleton * p = ConcreteSingleton:: Instance ();
)

Method 2:
namespace DesignPattern_Singleton
(
/ / Class Singleton
class Singleton
(
protected:
Singleton () ()
private:
Singleton (const Singleton &);
Singleton & operator = (const Singleton &);
);

/ / Class ConcreteSingleton
class ConcreteSingleton: public Singleton
(
public:
static Singleton * Instance () (static ConcreteSingleton _instance; return & _instance;)
protected:
ConcreteSingleton () ()
);
)

Client-side code:
(
using namespace DesignPattern_Singleton;
Singleton * p = ConcreteSingleton:: Instance ();
)

Method 3:
namespace DesignPattern_Singleton
(
template <class T>
class Singleton
(
public:
static T * Instance () (static T _instance; return & _instance;)
protected:
Singleton () ()
private:
Singleton (const Singleton &);
Singleton & operator = (const Singleton &);
);

class ConcreteSingleton: public Singleton <ConcreteSingleton> ();
)

Client-side code
(
using namespace DesignPattern_Singleton;

ConcreteSingleton * p = ConcreteSingleton:: Instance ();
)



C + + pattern of development of the Bridge
2002-07-29 · · · · COM camp

1, functional <BR> with its abstract part of the realization of part of the separation, so that they can be changed independently.

Second, the structure diagram

Third, the sample code

namespace DesignPattern_Bridge
(
/ / Class Implementor
class Implementor
(
public:
virtual void OperationImp () = 0;
);

/ / Class ConcreteImplementorA
class ConcreteImplementorA: public Implementor
(
public:
virtual void OperationImp () ()
);

/ / Class ConcreteImplementorB
class ConcreteImplementorB: public Implementor
(
public:
virtual void OperationImp () ()
);

/ / Class Abstraction
class Abstraction
(
public:
void Operation (Implementor * imp) (assert (imp); imp-> OperationImp ();)
);
)

Client-side code:
(
using namespace DesignPattern_Bridge;

Abstraction obj;
Implementor * impa = new ConcreteImplementorA ();
Implementor * impb = new ConcreteImplementorB ();
obj.Operation (impa); / / The first realization method
obj.Operation (impb); / / The second realization method
)

4, examples

(1) Create in X Window System and IBM's Presentation Manager system can be used in the window. (Book examples)

Bridge's charm lies in between the abstract and the achievement of a loose relationship between them can be freely combined. Such as the figure above, there is IconWindow + XWindowImp, TransientWindow + XWindowImp, IconWindow + PMWindowImp, TransientWindow + PMWindowImp four kinds of combinations.



C + + mode design of the Builder
2002-07-30 · · · · COM camp

A functional

Construction of a complex object with its representation of separation, making the same construction process can create different representation.

Second, the structure diagram


The interaction between various types as shown below:


Third, the sample code

namespace DesignPattern_Builder
(
class Product1 (/*...*/);
class Product2 (/*...*/);

/ / Class Builder
class Builder / / abstract base class
(
public:
virtual void BuilderPartA () () / / provide default implementation
virtual void BuilderPartB () ()
virtual void BuilderPartC () ()
protected:
Builder () ()
);

/ / Class ConcreteBuilder1
class ConcreteBuilder1: public Builder / / Create Product1
(
public:
ConcreteBuilder1 (): _product (NULL) ()

virtual void BuilderPartA () (/*...*/)
virtual void BuilderPartB () (/*...*/)
virtual void BuilderPartC () (/*...*/)

virtual Product1 * GetProduct1 () (return _product;) / / return the created object Product1
private:
Product1 * _product;
);

/ / Class ConcreteBuilder2
class ConcreteBuilder2: public Builder / / Create Product2
(
public:
ConcreteBuilder2 (): _product (NULL) ()

virtual void BuilderPartA () (/*...*/)
virtual void BuilderPartB () (/*...*/)
virtual void BuilderPartC () (/*...*/)

virtual Product2 * GetProduct2 () (return _product;) / / return the created object Product2
private:
Product2 * _product;
);

/ / Class Director
class Director
(
public:
/ / Create object (Director does not know the specific object is to create out of what kind, and only call the function of the client know)
void Construct (Builder * builder)
(
builder-> BuilderPartA ();
builder-> BuilderPartB ();
builder-> BuilderPartC ();
)
);
)

Client-side code:
(
using namespace DesignPattern_Builder;

Director director;

/ / Create the first object
ConcreteBuilder1 * pBuilder1 = new ConcreteBuilder1 ();
director.Construct (pBuilder1);
Product1 * product1 = pBuilder1-> GetProduct1 ();

/ / Create a second object
ConcreteBuilder2 * pBuilder2 = new ConcreteBuilder2 ();
director.Construct (pBuilder2);
Product2 * product2 = pBuilder2-> GetProduct2 ();
)

4, examples

(1) Example 1. As shown below:


Function on the map is to an RTF file conversion for a variety of text formats. RTFReader for parsing, and then convert them one by one all of the token string. Builder is a step by step can be seen in various parts of the assembly as a whole. It closed method of assembling the assembly out of very different objects.



C + + design patterns of the Prototype
2002-08-01 · · · · COM camp

A functional

With the prototype to create an instance of the specified object type, and by copy of these prototypes to create a new object.



Second, the structure diagram

Third, advantages and disadvantages

Benefits: Copy itself. Customers do not know the needs of the actual type of the object, just know that it can be an abstract base class. (Ie inheritance tree case)

Disadvantages: must have an object instance (ie, prototype) in order to clone.

4, sample code

namespace DesignPattern_Prototype
(
/ / Class Prototype
class Prototype / / abstract base class
(
public:
virtual Prototype * Clone () = 0;
);

/ / Class ConcretePrototype1
class ConcretePrototype1: public Prototype
(
public:
virtual Prototype * Clone ()
(
ConcretePrototype1 * p = new ConcretePrototype1 ();
* p = * this; / / copy the object
return p;
)
);

/ / Class ConcretePrototype2
class ConcretePrototype2: public Prototype
(
public:
virtual Prototype * Clone ()
(
ConcretePrototype2 * p = new ConcretePrototype2 ();
* p = * this; / / copy the object
return p;
)
);
)

Client-side code:
(
using namespace DesignPattern_Prototype;

ConcretePrototype1 * obj1 = new ConcretePrototype1 (); / / prototype of an object 1
ConcretePrototype2 * obj2 = new ConcretePrototype2 (); / / prototype object 2

Prototype * newobj1 = obj1-> Clone (); / / clone the object a
Prototype * newobj2 = obj2-> Clone (); / / clone the object 2

/ / Use to copy the object out of newobj1 and newobj2
)

5, examples

In a graphics editor, each a graphic element, such as line, circle, text, and so should support the copy operation, which point graphics, press Ctrl + C, and then press Ctrl + V will be copied after a new graphics . Obviously this is a clone operation. Therefore, each derived from the Graphic Graphic subclass of Prototype models should be applied, together with Clone operation.


C + + Design Patterns Factory Method
2002-08-05 · · · · COM camp

A functional

Defines an interface for creating an object, so that sub-type of decision which instantiate a class. Factory Method to make an instance of a class of delay to its subclasses.

Second, the structure diagram

Third, to achieve

(1) In certain circumstances, such as just in order to create the appropriate Product objects derive a new subclass of Creator, and create different ways Product line, you can consider using templates instead of inheritance. Such as:

class Creator
(
public:
virtual Product * CreateProduct () = 0;
);

template <class ConcreteProduct>
class ConcreteCreator: public Creator
(
public:
virtual Product * CreateProduct () (return new ConcreteProduct ();)
);

Templates and inheritance is one of the essential differences between: Template: behavior does not depend on the type. Succession: the behavior depend on the type. (Effective C + + Item 41) In fact, in many ways both the existence of the template can be replaced by a succession of, the underlying reason is that sub-class behavior is consistent.

4, sample code

namespace DesignPattern_FactoryMethod
(
class Product (/*...*/);
class ConcreteProduct: public Product (/*...*/);

/ / Class Creator
class Creator
(
public:
virtual Product * CreateProduct () = 0;
void Operate ();
);

void Creator:: Operate ()
(
/ / ...
Product * p = CreateProduct ();
/ / ...
)

/ / Class ConcreteCreator
class ConcreteCreator: public Creator
(
public:
virtual Product * CreateProduct () (return new ConcreteProduct ();)
);
)

Client-side code:
(
using namespace DesignPattern_FactoryMethod;
ConcreteCreator p;
p.Operate ();
)

   CreateProduct here is actually a Template Method.

5, examples

Factory Method use too broad, and it is often used in other models, in fact, examples abound.
(1)

MFC's CDocument class contains the similar to the previous figure CApplication the three functions. CreateDocument here is a factory method, because it is responsible for creating a document object.

(2)

When a class some of its responsibilities entrusted to a separate class, it creates a parallel class hierarchy. Figure figure above, and Manipulator is a parallel class hierarchy, Figure on behalf of a number of graphic elements, such as lines, text, etc., Manipulator said the role of graphical elements in these operations, such as drag, move, select and so on. If these operations need not require state information saved in the Figure, then the Figure and the Manipulator is divided into two class hierarchies is a good idea. CreateManipulator here is a factory method.



C + + design patterns of the Composite
2002-08-06 · · · · COM camp

1, function <BR> said that "part - whole" relationship, and make the user in a consistent manner using a single object and the combination of the object.

Second, the structure diagram

Figure above, you can do to expand as needed can be Leaf and Composite as an abstract base class, derived from sub-classes.

Third, advantages and disadvantages

Benefits: For the Composite pattern, people may start one's attention will focus on how it is to achieve combination of objects. But the Composite of the most important is that the user does not care is a combination of an object or a single object, the user will be a unified manner, so I base class should be a combination of objects from a single object and raised in the public interface.
Disadvantages: Composite biggest problem is not easy to limit the portfolio components.

Fourth, to achieve

Sometimes need to limit the combination of components, namely the desire Composite can only have a certain Leaf. The issue on which I used multiple inheritance and dynamic type conversions to be resolved. If the combination of object Composite1 can contain a single object ConcreteLeaf1, Composite2 can contain a single object ConcreteLeaf1 and ConcreteLeaf2. As shown below:

Figure above the class hierarchy are more used AbstractLeaf1 and AbstractLeaf2, but did not use AbstractComposite1 and AbstractComposite2, this is not important, but also can AbstractLeaf1 and AbstractLeaf2 removed, this is not important, you can decide whether or not to light of specific circumstances.
A simple code to achieve the following:

namespace DesignPattern_Composite
(
class Component
(
public:
virtual void operation () = 0;
virtual void Add (Component *) ()
);

class AbstractComponent1: virtual public Component ();

class AbstractLeaf1: virtual public AbstractComponent1 ();

class Composite1: public AbstractComponent1
(
public:
virtual void operation () (/ * do operation * /)
virtual void Add (Component *);
);
void Composite1:: Add (Component * p)
(
AbstractComponent1 * pc1 = dynamic_cast <ABSTRACTCOMPONENT1*> (p);
if (pc1 == NULL) return;
/ / Do add operation
)

class AbstractComponent2: virtual public Component ();

class AbstractLeaf2: virtual public AbstractComponent2 ();

class Composite2: public AbstractComponent2
(
public:
virtual void operation () (/ * do operation * /)
virtual void Add (Component *);
);
void Composite2:: Add (Component * p)
(
AbstractComponent2 * pc2 = dynamic_cast <ABSTRACTCOMPONENT2*> (p);
if (pc2 == NULL) return;
/ / Do add operation
)

class ConcreteLeaf1: public AbstractLeaf1
(
public:
virtual void operation () (/ * do operation * /)
);

class ConcreteLeaf2: public AbstractLeaf1, public AbstractLeaf2
(
public:
virtual void operation () (/ * do operation * /)
);
)

Client-side code:
(
using namespace DesignPattern_Composite;

Component * pc1 = new ConcreteLeaf1 ();
Component * pc2 = new ConcreteLeaf2 ();
Component * pc3 = new Composite1 ();
Component * pc4 = new Composite2 ();
pc3-> Add (pc1); / / ok
pc3-> Add (pc2); / / ok
pc3-> Add (pc3); / / ok
pc3-> Add (pc4); / / fail
pc4-> Add (pc1); / / fail
pc4-> Add (pc2); / / ok
pc4-> Add (pc3); / / fail
pc4-> Add (pc4); / / ok
)

There are two points to note, first, because it used multiple inheritance, so need to use virtual inheritance. The second is to use dynamic_cast to determine whether to allow combination of the component.

5, sample code

namespace DesignPattern_Composite
(
/ / Class Component
class Component
(
public:
virtual void Operation () = 0;
virtual void Add (Component *) ()
);

/ / Class Leaf
class Leaf: public Component
(
public:
virtual void Operation () ()
);

/ / Class Composite
class Composite: public Component
(
public:
virtual void Add (Component * p) (_list.push_back (p);)
virtual void Operation ()
(
vector <Component *>:: const_iterator it;
for (it = _list.begin (); it! = _list.end (); it + +)
(* it) -> Operation ();
)
private:
vector <Component *> _list;
);
)

6, examples

(1) JUnit on using a Composite pattern.



C/C++ Tutorial Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.