How can I use a POJO Class and a Classic Class and what is the difference? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How can I use a POJO Class and a Classic Class and what is the difference?

Hello everyone. I have a school project to do in Java. I use the POJO class, DAO and the classic Class. I don't really understand how I can use the classics classes (wich contained attributes and methods) with POJO. I know the definition of a POJO but is it useful to have the same attributes in my POJO class than my classic class?

30th Oct 2017, 10:31 PM
Brandon Buxin
Brandon Buxin - avatar
4 Answers
+ 2
Yes, I'm sorry. I call "classic class" as a normal class with some attributes and some methods wich can modify the values of theses attributes. The POJO just contained attributes and getters + setters but not algorithmic methods which modify the value of the POJO's attributes. So, in my normal class, should I just put my methods + one attributes that referred to my POJO class as I could use my methods to modify the attributes via getters and setters of my POJO?
31st Oct 2017, 9:33 AM
Brandon Buxin
Brandon Buxin - avatar
+ 2
Well, if I understand what you are saying, I should use POJO for subtil information as for example , the ID from a table of my table. My class wich contain some functionnalities is able to contain attributes. Or, I can just put methods in my class and use POJO's getters and setters to modify the informations. Is it a good manner to work in a project?
31st Oct 2017, 12:18 PM
Brandon Buxin
Brandon Buxin - avatar
0
So what do so think of as classic? Pojo means "plain old Java object". You can literally not get more classic than that. The opposite of Pojo is "class implementing stuff from my fancy framework". For whatever framework that may be.
31st Oct 2017, 1:38 AM
1of3
1of3 - avatar
0
As I understand it you use some DAOs to send/retrieve Pojos to/from the db. Actually, there is no proper definition of Pojo. It's not a scientific term or anything. Pojo is a nickname for model or domain objects as they are otherwise called: The things your program is about. If your program is about books you probably have a class Book. And the Book should have all the functionality it needs to be a book. The reason you factor out the db access is that it's not an inherent part of Book or whatever. (Although other schools of thought will disagree about that.) So there are only two kinds of things here: The model classes your program is about and utility classes providing db functionality. The only reason not to put the business logic in the model classes, is changing the logic while keeping the model.
31st Oct 2017, 11:24 AM
1of3
1of3 - avatar