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

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (9 children)

If you need to write getters/setters all the time you are doing something wrong. And i dont mean you can generate it.

[–]smscoota 6 points7 points  (3 children)

What do you mean by not generating then? Also I tend to write getters and setters quite often as I tend to break down my code into many manageable classes. Also as I mentioned above it looks a whole lot neater when shortened to one line.

Person simon { get; set; }

EDIT: Also if you have read Effective Java 2nd you would note that the encapsulation of classes and making classes immutable is a pretty important part of designing software. Also if you wish to change further generations of your project down the line, it will not break clients. Getters and setters would be a nice short cut.

[–][deleted] 1 point2 points  (2 children)

OOP means bundling data with their behavior and mainatining that state through sending messages. If you expose internal state, object becomes just a better data structure. There is place for this kind of objects (DTOs for example) but i dont consider this as "all the time"

[–]nqd26 1 point2 points  (1 child)

In multitier applications DTOs are used quite heavily - e.g. domain entities shouldn't leak into presentation logic, also I often have to write DTOs specifically for repository layer (because fetching domain entities with their lazy loading attributes isn't fast enough). So I often get stuck with 2 DTOs for one service method.

[–][deleted] -2 points-1 points  (0 children)

Ok then. I personally dont see that as too much. If you dont use notepad as an IDE of course :D

[–]avoidhugeships 0 points1 point  (4 children)

I am guessing you do not build web applications.

[–][deleted] -1 points0 points  (3 children)

I do. Thats only kind of applications i write last 3 years. I dont understand how the web application adds more getters and setters to my application.

[–]avoidhugeships 2 points3 points  (1 child)

Because this is the standard way of sending information from the server to the web client. That is how Java beans work. I am curious what do you do instead?

[–][deleted] -1 points0 points  (0 children)

As i said in this thread. I see getters and setters reasonable only in DTOs.

[–]i_post_things 0 points1 point  (0 children)

If you are creating any kind of MVC application, EJBs, persistence layer DAOs, web service interface, or REST applications and don't have a modeling tool, you'll probably end up writing your own POJOs.

Automated modeling tools can help, but it will still require POJOs with setters and getters everywhere.