• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Wrapper Class ?

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i ve been reading a lot of threads talking about wrapper class. What is wrapper class means over here? can u give me an example plsss.
 
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kruger,
examples of wrapper classes are Integer, Double etc. A wrapper actually holds some other object (or value) and offers some methods to do something with the wrapped object.

I hope this makes clear what a wrapper is and how it works.
 
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Kruger Scheitz:
i ve been reading a lot of threads talking about wrapper class. What is wrapper class means over here? can u give me an example plsss.


I think people use wrappers in this assignment by using the DAO pattern... they want to separate the database from the gui... I wrapped the DataInfo data in a wrapper so that I could swap out the Sun database for any other database with a few simple interface implementations.
 
Kruger Scheitz
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thx brother... sometimes i wonder how could i passed the SCJP...sighhhhhhhhhh
 
Kruger Scheitz
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why we need a wrapper class to wrap up another object class? isn't it more efficient to call up the object that you want to call instead of using wrapper object to call another object. and isn't it more memory consumption if u call wrapper object which then call another object since u have to pass object reference from methods to methods ?
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Kruger Scheitz:
i ve been reading a lot of threads talking about wrapper class. What is wrapper class means over here? can u give me an example plsss.


Why not read the definitive reference for design patterns (GoF book)? wrapper = decorator and you can find a whole chapter on this pattern in the book.
 
Mag Hoehme
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Kruger Scheitz:
isn't it more efficient to call up the object that you want to call instead of using wrapper object to call another object. and isn't it more memory consumption if u call wrapper object which then call another object since u have to pass object reference from methods to methods ?


Actually yes. But there are a lot of reasons to use wrappers... For example:
  • You want to handle primitives in collections such as lists or hashtables
  • The interface of your wrapped object does not fit - you can wrap it with a so-called Adapter

  • Wrappers do add indirection, require (usually slightly) more memory - that is their downside. But this is a trade-off that can be accepted.
     
    Don't get me started about those stupid light bulbs.
    reply
      Bookmark Topic Watch Topic
    • New Topic