• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Wrapper Class ?

 
Kruger Scheitz
Ranch Hand
Posts: 72
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Mag Hoehme
Ranch Hand
Posts: 194
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Nate Johnson
Ranch Hand
Posts: 301
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thx brother... sometimes i wonder how could i passed the SCJP...sighhhhhhhhhh
 
Kruger Scheitz
Ranch Hand
Posts: 72
  • 0
  • Mark post as helpful
  • send pies
  • 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 ?
 
Ruby Wong
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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.
     
    I agree. Here's the link: http://aspose.com/file-tools
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic