Wrapper Class
-
Hi How to create a wrapper class for an existing class? thanks : :^)
-
Hi How to create a wrapper class for an existing class? thanks : :^)
Your question is too generic: it depends on your scenario. Which kind of class do you want to wrap (COM object, ActiveX, ...)? What is your target?
-
Hi How to create a wrapper class for an existing class? thanks : :^)
Typically what you do is to create a new class exposing methods of an interface that you are interested in. Depending of what you want to wrap, the interface might be a C header file, a COM interface or another class, etc. The wrapper class often manages resource allocation and deallocation of the exposed interface, and this is often the most valuable aspect of wrapping. You can also make it easier to use the interface by bundling methods together as you see fit, removing rarely used parameters and such.
-
Hi How to create a wrapper class for an existing class? thanks : :^)
As a member of the wrapper class, an object of the existing class is created. The member object is then initialized in the constructor of the wrapper class. From the methods of the wrapper class, the methods of the existing class will be called using the member object.
«_Superman_»
I love work. It gives me something to do between weekends. -
Hi How to create a wrapper class for an existing class? thanks : :^)
The problem here is that one man's wrapper is another's bridge, adapter, guard or facade. Generally you use wrappers to modify the functionality of the wrapped class in some way so how you do it depends on what the class you're wrapping does and what you want the wrapper to do. If I were you I'd have a look at a book on design patterns - e.g. "Design Patterns" by Gamma, Helm, Johnson and Vlisides - and go through the patterns looking at which of the classes used are just there to modify the behaviour of other classes by containing them rather than by extending them. Cheers, Ash