+ Start a Discussion
vickySFDCvickySFDC 

Whats is diff betwn Inner class and Wrapper class?Pls Explain

Hi All,

 

Is there any diff between Inner class and Wrapper classes?pls explain...

what does mean Inner Wrpper class?

 

Thanks,

Vicky

Best Answer chosen by Admin (Salesforce Developers) 
CatoPCCatoPC

This is more of a OOD/ data modeling question. Here is a practical approach I use with both concepts on Force.com. I use Wrapper classes is used primary as another alternative to inheritance, if I can not extend a class  (described as 'is a' ) then use of a wrapper class would be used to enforce a 'has a' relationship. There are more uses, especially when implementing design patterns, but most of the time is how I have used wrapper class concept. Here is a great write up on wrapper class, Wrapper Class tutorial.  

 

Inner class is helper/utility class, keeps code lean and clean. In practice, I have mainly used inner class with Visual Force Controllers, mainly to represent data to View (VF Page) in a desired way outside of SObject's structure stored. Here is an example here, Inner Class VF Tutorial.

 

In essence this is all about encapsulation and the data model in the end, so I would suggest to keep that in mind. Clean code is ideal. Hopefully this points you in the right direction. 

 

Caleb

All Answers

vickySFDCvickySFDC
Thanks for reply,

Can u explain in detail?Because I am confusing on Both inner and wrapper class

Thanks,


Vicky
CatoPCCatoPC

This is more of a OOD/ data modeling question. Here is a practical approach I use with both concepts on Force.com. I use Wrapper classes is used primary as another alternative to inheritance, if I can not extend a class  (described as 'is a' ) then use of a wrapper class would be used to enforce a 'has a' relationship. There are more uses, especially when implementing design patterns, but most of the time is how I have used wrapper class concept. Here is a great write up on wrapper class, Wrapper Class tutorial.  

 

Inner class is helper/utility class, keeps code lean and clean. In practice, I have mainly used inner class with Visual Force Controllers, mainly to represent data to View (VF Page) in a desired way outside of SObject's structure stored. Here is an example here, Inner Class VF Tutorial.

 

In essence this is all about encapsulation and the data model in the end, so I would suggest to keep that in mind. Clean code is ideal. Hopefully this points you in the right direction. 

 

Caleb

This was selected as the best answer
vickySFDCvickySFDC

Hi Caleb,

 

Thanks for expalination..

 

 

This Inner class concept  only collecting data in Only  single  object or we can use multiple object data displaying in the table? 

 

But in Wrapper classes concept  we can collect data more than one object and displaying in the table.

 

 

Thanks,

 

 

Vicky

CatoPCCatoPC

Bad practice to include more than one object within an inner class in general. However it can be useful when displaying cross data within a table on a VF page.

 

The Wrapper class is much more robust concept past VisualForce pages, especially within large implementations.

 

If my previous exploitation answered the question could you mark it as the solution? Thank you.

 

Caleb 

vickySFDCvickySFDC
Thanks