Wha is a "Wrapper class" and what is it used for?

Discussion in 'Web Design & Coding' started by Complete, Sep 21, 2007.

  1. Complete

    Complete OSNN Addict

    Messages:
    94
    Wha is a "Wrapper class" and what is it used for?
     
  2. X-Istence

    X-Istence * Political User

    Messages:
    6,498
    Location:
    USA
    Sometimes you have an object that already does what you need to it to do, for example the GTK+ library.

    Now, you come along and already have this great app that interfaces to Windows using another class.

    Now you want to port that program to GTK+, you write a small wrapper around GTK+ that implements the functions required, and swap out the Windows class with the GTK+ class, and now your program has GTK+ as it's window drawing tool, and the class essentially is like a wrapper around a candy bar. It protects and provides a clean way to access the underlying candy!
     
  3. Geffy

    Geffy Moderator Folding Team

    Messages:
    7,805
    Location:
    United Kingdom
    Its an abstraction tool for isolating your code from the complicated inner workings of something else.

    In Java you have the Integer wrapper class which isolates your code from the inner workings of the 'int' data type.