www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Writing adaptor/wrappers with most scalability and least work

reply Pie? <AmericanPie gmail.com> writes:
I would like to temporarily write some adapters or wrappers for 
various types that allow the most extensibility with the least 
amount of work. The goal is to get moving quickly as possible and 
not try to implement all future needs. The wrappers will slowly 
turn into full their own types and not be wrappers at all.

Obviously this requires declaring an interface and such. I 
curious if I could somehow easily delegate work to the the types 
I would like to wrap without designing a full fledged oo type.

e.g.,

class Image
{
     alias this pImage;
}

So, for all purposes Image acts as pImage(except for constructor 
calls). Of course now I'm bound to pImage's interface which I 
might not like/want but it gets me pretty far and I can extend it 
immediately with things I do not want in Image that are in pImage.

Any ideas on a good way to approach this? Is there some D tricks 
that make life easier?
Jun 03 2016
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Saturday, 4 June 2016 at 01:04:08 UTC, Pie? wrote:
     alias this pImage;
It is actually `alias pImage this;` That should do what you want right here. Then you can add your own methods or wrap/disable the image ones one by one.
Jun 03 2016
parent Pie? <AmericanPie gmail.com> writes:
On Saturday, 4 June 2016 at 02:10:57 UTC, Adam D. Ruppe wrote:
 On Saturday, 4 June 2016 at 01:04:08 UTC, Pie? wrote:
     alias this pImage;
It is actually `alias pImage this;` That should do what you want right here. Then you can add your own methods or wrap/disable the image ones one by one.
Is there a better way or is this the standard technique? I was hoping to use some type of design by introspection but haven't come up with a solid way to accomplish this.
Jun 04 2016