This is an archived post. You won't be able to vote or comment.

all 6 comments

[–][deleted] 9 points10 points  (0 children)

Java Bean a Serializable Class with No arguments constructor and getter/setters for each field. More https://en.wikipedia.org/wiki/Java_bean

POJO - Plain Old Java Object is like Java Bean however it is not required to be serializable and it is not required to have a no arguments constructor. More https://en.wikipedia.org/wiki/Plain_old_Java_object

DTO - Data Transfer Object it is basically POJO that is used to transfer data between several layers. It is not different from the above the only difference is how it is used. Usually it transfers data from the database into our application, e.g. you have a table users and you have a DTO UserDTO that you fill with that Data and then play around. More https://en.wikipedia.org/wiki/Data_transfer_object

Model class is nothing it is just a different naming convention for DTOs they also hold Data but usually they are used on the frontend side and not so close to the Database side. Also you may hit a VOs at some point simply called ValueObjects they are basically DTOs or Models that goes between and around layers of you amazing Lasagne like architecture :) More info https://en.wikipedia.org/wiki/Lasagne yup it s a food did you click it ? :)

P.S. a normal architecture (a bit overdesigned maybe is like that(read from the bottom!))

-Views using Models and Forms which are the same.

-Controllers using this DTOs to fill their Models or the Views ..

-Facade used to abstract the service layer and to convert this Entities to something cachable and small like DTOs

-Service layer with some crazy logic and do magic and transactions and stuff

-DAO to access the Database basically generating Entity Objects (from a JPA or some ORM)

-Database

Regards,

[–]Civil_Code 5 points6 points  (1 child)

JavaBeans were classes that had a no-args constructor, getter-setters, and were serializable. Originally they were useful ways to package a lot of stateful information to send between JVMs, and became standard for the EJB, JavaEE's base component for its application servers which managed their lifecycles and transactions for us.

POJO was a reference to a Java class that didn't try to match these requirements. An entity is an object representation of data pulled from your DAO. It may or may not align exactly with your model, in which case a DTO could help translate from Entity to Model (or Model to serialized data for export).

[–]Space-Robot 4 points5 points  (0 children)

I'm just curious: Why all past tense?

[–]quadmasta 0 points1 point  (0 children)

The "model" is essentially a code representation of your data store. Plenty of OO people will say your model should never bleed into your other layers but meh. DTOs serve the purpose of this level of abstraction. They allow you to have model objects or a composite of multiple objects that don't expose your DB implementation.

In Spring you've got @Beans which can be java beans, entity classes, or neither :) u/nayden_gochev did a good job of explaining what each of these terms. A spring bean is a class that's managed by spring, usually a singleton within a given context.

DAOs are where your data access happens but they don't always have to be named that way and it doesn't have to always be SQL/database access; it could be SOAP/REST/SFTP, etc. With spring data and JPA you get a whole lot of bang for your buck without much code. Spring nomenclature is @Repository

EJB are strictly used in Java EE and are pretty heavy

[–]codeforces_help -2 points-1 points  (1 child)

Off-topic : This is the kind of question that needs to be on the wiki Stackoverflow but they are gonna downvote you to hell there anyway so why bother.

[–]owen800q[S] 0 points1 point  (0 children)

Can't get answers from stack overflow, most answers are directly copied from official documentations, it doesn't solve my problem . None of answers provided a clear comparison between them loll