Questions tagged [wrapper]

A wrapper is an OOP technique where an object encapsulates (wraps) another object, resource (dynamically allocated memory, OS file/widow handle, socket, thread mutex, etc) or a set of subroutines, hiding/protecting it and providing another (possibly easier to use) interface. When using this tag on implementation heavy questions - tag the code language the implementation is written in.

A Wrapper is an Object which contains another data type, Object, resources, or subroutines for the purpose of encapsulation. The corresponding class of that Wrapper is the wrapper class.

Often when we refer to a wrapper class we often refer to a primitive wrapper class, where instances of that class encapsulate a primitive type.

Many object-oriented languages, such as Java, differentiate between primitive types (such as char) and Objects (such as String), for example that primitive values are passed on by value and are the simplest data types, whereas Objects are passed on by reference and that it includes their own fields and methods. The names of primitive data types are also usually keywords, as opposed to Objects.

In some cases, you may need an instance of a wrapper class for these primitives to perform boxing, treat these primitives as Objects due to OOP reasons, converting a primitive to another Object type, or when using an otherwise primitive value when polymorphism is required. The name of the corresponding primitive wrapper class for a given primitive data type are written in full and follow naming conventions for classes (such as beginning with an uppercase in Java).

Java wrapper classes:

Java offers these wrapper classes which you can use without importing anything. Note that their names begin with an uppercase, and are written in full.

  • Boolean for booleans
  • Character for char
  • Integer for int
  • Long for 64-bit int
  • Double for boudle
  • Byte for byte
  • Short for short
  • Float for float

Tags related to wrapper operations:

Link to Wikipedia page

3619 questions
27
votes
1 answer

BOOL wrapper? Make an object of `BOOL` value. (Objective-C)

How do I wrap a BOOL in an object type in Objective-C? I want to store a BOOL in the userInfo object of an NSTimer. How do I wrap it?
Shade
  • 9,936
  • 5
  • 60
  • 85
26
votes
6 answers

How to fake type with Python

I recently developed a class named DocumentWrapper around some ORM document object in Python to transparently add some features to it without changing its interface in any way. I just have one issue with this. Let's say I have some User object…
Pierre
  • 6,084
  • 5
  • 32
  • 52
26
votes
3 answers

Automatically generate C# wrapper class from dll in Visual Studio 2010 Express?

I was told by a colleague of mine that Visual Studio allows one to point to a .dll and auto-magically generate a C# wrapper class. Is this really possible? And if so, how does one go about achieving this? I've browsed the web, but have failed to…
mre
  • 43,520
  • 33
  • 120
  • 170
25
votes
11 answers

Java vs. C++ for building a GUI which has a C++ backend

I currently have a C++ backend that I need to connect with a GUI, and since I've never built a GUI before, I was confused on where to start. I'm comfortable writing code in C++ and Java, so I'd prefer my GUI to be in one of those languages. Also,…
sparkFinder
  • 3,336
  • 10
  • 42
  • 57
23
votes
4 answers

Are all primitive wrapper classes immutable objects?

Are all primitive wrapper classes in Java immutable objects? String is immutable. What are the other immutable objects?
Jothi
  • 14,720
  • 22
  • 68
  • 93
23
votes
1 answer

vue wrap another component, passing props and events

How can I write my component to wrap another vue component, while my wrapper component get some extra props? My wrapper template component should be: