Skip to main content

All Questions

Tagged with
276 votes
14 answers
125k views

Should we avoid object creation in Java?

I was told by a colleague that in Java object creation is the most expensive operation you could perform. So I can only conclude to create as few objects as possible. This seems somewhat to defeat ...
Slamice's user avatar
  • 2,657
202 votes
14 answers
141k views

When are Getters and Setters Justified?

Getters and setters are often criticized as being not proper OO. On the other hand, most OO code I've seen has extensive getters and setters. When are getters and setters justified? Do you try to ...
104 votes
17 answers
20k views

Is encapsulation still one of the elephants OOP stands on?

Encapsulation tells me to make all or almost all fields private and expose these by getters/setters. But now libraries such as Lombok appear which allow us to expose all private fields by one short ...
Gangnus's user avatar
  • 2,807
103 votes
18 answers
69k views

Is it poor programming practice to pass parameters as Objects? [duplicate]

So, we've got a guy who likes to write methods that take Objects as parameters, so they can be 'very flexible.' Then, internally, he either does direct casting, reflection or method overloading to ...
92 votes
10 answers
55k views

How do you avoid getters and setters?

I'm having something of a hard time with designing classes in an oo way. I've read that objects expose their behavior, not their data; therefore, rather than using getter/setters to modify data, the ...
IntelliData's user avatar
83 votes
12 answers
31k views

What is the utility and advantage of getters & setters especially when they are merely used to read and assign values to properties of an object? [closed]

I’m still really new to learning to program. Just learning the syntax for a few programming languages at the moment. The courses I viewed for C# and Java touched only very briefly on getters & ...
ProjectDiversion's user avatar
66 votes
11 answers
65k views

In Object-Oriented Programming, why is it generally desirable to split a program into multiple classes? [closed]

After studying Programming through books, they have taught me concepts such as inheritance, but never explain how splitting a program into multiple classes helps with anything. Yet, many books seem to ...
kullalok's user avatar
  • 1,085
59 votes
9 answers
49k views

Should the methods of a class call its own getters and setters?

Where I work I see lots of classes that do things like this: public class ClassThatCallsItsOwnGettersAndSetters { private String field; public String getField() { return field; }...
Daniel Kaplan's user avatar
56 votes
3 answers
74k views

Which is a better practice - helper methods as instance or static?

This question is subjective but I was just curious how most programmers approach this. The sample below is in pseudo-C# but this should apply to Java, C++, and other OOP languages as well. Anyway, ...
Ilian's user avatar
  • 663
47 votes
10 answers
28k views

Is there any reason to use "plain old data" classes?

In legacy code I occasionally see classes that are nothing but wrappers for data. something like: class Bottle { int height; int diameter; Cap capType; getters/setters, maybe a ...
Michael K's user avatar
  • 15.6k
43 votes
3 answers
63k views

What is message passing in OO?

I've been studying OO programming, primarily in C++, C# and Java. I thought I had a good grasp on it with my understanding of encapsulation, inheritance and polymorphism. One frequently referenced ...
Tom's user avatar
  • 852
43 votes
9 answers
117k views

Why should I declare a class as an abstract class?

I know the syntax, rules applied to abstract class and I want know usage of an abstract class Abstract class can not be instantiated directly but can be extended by other class What is the ...
Vaibhav Jani's user avatar
41 votes
8 answers
6k views

Do access modifiers matter? [closed]

The theory is that access modifiers improve code safety because they support encapsulation of internal state. When doing OOP, every language I've used implements some kind of access restriction. I ...
ahoffer's user avatar
  • 653
38 votes
10 answers
14k views

Is it a good idea to have logic in the equals method that doesn't do exact matching?

While assisting a student with a university project, we worked on a Java exercise provided by the university which defined a class for an address with the fields: number street city zipcode And it ...
Will's user avatar
  • 829
38 votes
5 answers
9k views

When should I extend a Java Swing class?

My current understanding of Inheritance implementation is that one should only extend a class if an IS-A relation is present. If the parent class can further have more specific child types with ...
Paras's user avatar
  • 491

15 30 50 per page
1
2 3 4 5
33