Archived

This topic is now archived and is closed to further replies.

Creating wrappers

This topic is 5145 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

quote:
Original post by PumpkinPieman
Just wondering, when do you know when to make a wraper? I''m having confused idea''s of when to use one, and when not too.


"when do you know when to make a wraper?" - When you don''t want to type the whole WinMain code for example.

Share this post


Link to post
Share on other sites
Well that''s just one example, and most people do that. Now say creating a wrapper for certain functions of the STL like multimap. I don''t want to deal with all that excessive typing, so I want to simplify it. But whilst I simplifiy it, I loose some general features that I like about the multimap. In that vase, and that you are using many classes that use it, should you or should you not create a wrapper for it?

Share this post


Link to post
Share on other sites
A wrapper is a pretty general term but here I go...usually you write a wrapper layer to either simplify code or to isolate/abstract it.

If there''s a function that you use frequently that takes 10 arguments but you only change two of them in all of you calls then wrap it and default the other aguments. If you find yourself writing the same code over and over, look at it, find the patterns and wrap it in some functions or a class.

In the isolate/abstract case if there''s something you want to contain or want to be able to swap out later create an interface that wraps the functionality. The classic example in PC game programming is wrapping OpenGL and DirectX so your game can use either.



Share this post


Link to post
Share on other sites
Sorry about the overlapped typing. As for you multimap example. Will it reduce errors, make the code easiler to read, etc? Then sure, wrap it. If you''re trying to simplify your common usage of multimap but don''t want to lose the flexibility write a proxy class or have your helper class have a member to get to the multimap for the exceptional cases.

Share this post


Link to post
Share on other sites
Wrappers can be useful for certain libraries - DirectX is a good example as you don''t want to keep having to manually create/retrieve the DX interface and create your surfaces/palette every time you start a new project so writing a wrapper class that can accomplish this in a few function calls will make life easier

Share this post


Link to post
Share on other sites