Skip to main content

Questions tagged [object-oriented]

A methodology that enables a system to be modeled as a set of objects that can be controlled and manipulated in a modular manner

Filter by
Sorted by
Tagged with
332 votes
4 answers
137k views

Often, in libraries especially, packages contains classes that are organized around a single concept. Examples: xml, sql, user, config, db. I think we all feel pretty naturally that these packages ...
Nicole's user avatar
  • 28.3k
303 votes
9 answers
300k views

I understand what composition is in OOP, but I am not able to get a clear idea of what Aggregation is. Can someone explain?
Vinoth Kumar C M's user avatar
277 votes
14 answers
126k views

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,667
276 votes
17 answers
27k views

Is the visibility private of class fields/properties/attributes useful? In OOP, sooner or later, you are going to make a subclass of a class and in that case, it is good to understand and be able to ...
Adam Libuša's user avatar
  • 2,077
249 votes
23 answers
220k views

If immutable objects¹ are good, simple and offer benefits in concurrent programming why do programmers keep creating mutable objects²? I have four years of experience in Java programming and as I see ...
246 votes
15 answers
255k views

Why do we need private variables in classes? Every book on programming I've read says this is a private variable, this is how you define it but stops there. The wording of these explanations always ...
mwallace's user avatar
  • 2,514
202 votes
14 answers
142k views

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 ...
169 votes
18 answers
305k views

I am looking for a recommendation here. I am struggling with whether it is better to return NULL or an empty value from a method when the return value is not present or cannot be determined. Take ...
P B's user avatar
  • 2,379
165 votes
7 answers
122k views

I'm working with web development since 2009, when I started with PHP. When I moved to ASP.NET, I've heard a lot about DDD and OOAD where a lot of focus is given to this "business logic" and &...
user1620696's user avatar
  • 4,967
157 votes
15 answers
52k views

In the last few months, the mantra "favor composition over inheritance" seems to have sprung up out of nowhere and become almost some sort of meme within the programming community. And every time I ...
153 votes
14 answers
125k views

In object-oriented programming, there is of course no exact rule on the maximum length of a method , but I still found these two quotes somewhat contradicting each other, so I would like to hear what ...
Spring's user avatar
  • 1,763
150 votes
8 answers
25k views

I just started my first job as a software developer over a month ago. Everything I have learned about OOP, SOLID, DRY, YAGNI, design patterns, SRP, etc. can be thrown out the window. They use C# .NET ...
Grim's user avatar
  • 903
143 votes
4 answers
35k views

Reportedly, Alan Kay is the inventor of the term "object oriented". And he is often quoted as having said that what we call OO today is not what he meant. For example, I just found this on ...
Charlie Flowers's user avatar
115 votes
13 answers
66k views

It seems that C has its own quasi-objects such as 'structs' that can be considered as objects (in the high-level way that we would normally think). And also, C files themselves are basically separate ...
Dark Templar's user avatar
  • 6,323
114 votes
14 answers
31k views

I'm just now learning TDD. It's my understanding that private methods are untestable and shouldn't be worried about because the public API will provide enough information for verifying an object's ...
pup's user avatar
  • 1,722
114 votes
9 answers
187k views

I just wanted to clear up a question I have. What is the point of having a private static method as opposed to a normal method with private visibility? I would have thought an advantage to having a ...
Rehan Naqvi's user avatar
  • 1,259
106 votes
10 answers
16k views

The basic idea behind OOP is that data and behavior (upon that data) are inseparable and they are coupled by the idea of an object of a class. Object have data and methods that work with that (and ...
RokL's user avatar
  • 2,451
105 votes
17 answers
21k views

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,817
103 votes
13 answers
25k views

For example, to keep a CPU on in Android, I can use code like this: PowerManager powerManager = (PowerManager)getSystemService(POWER_SERVICE); WakeLock wakeLock = powerManager.newWakeLock(...
ggrr's user avatar
  • 5,893
103 votes
18 answers
70k views

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 ...
101 votes
22 answers
59k views

When I started using an object-oriented language (Java), I pretty much just went "Cool" and started coding. I've never really thought about it until only recently after having read lots of questions ...
99 votes
9 answers
20k views

I have been in two software product houses for three years in a row. The first is a small company maintaining a fairly small management system with a monolithic legacy code base (almost twenty years). ...
Rui's user avatar
  • 1,935
99 votes
4 answers
75k views

Is it bad practice that a controller calls a repository instead of a service? To explain more: I figure out that in good design controllers call services and services use repositories. But sometimes ...
mohsenJsh's user avatar
  • 1,365
98 votes
5 answers
32k views

I've heard a lot of talk about using functional languages such as Haskell as of late. What are some of the big differences, pros and cons of functional programming vs. object-oriented programming?
GSto's user avatar
  • 8,541
98 votes
4 answers
31k views

In the debate of Rich vs. Anemic domain models, the internet is full of philosophical advice but short on authoritative examples. The objective of this question is to find definitive guidelines and ...
RJB's user avatar
  • 2,110
96 votes
15 answers
54k views

I code a lot in both C and C++, but did not expect C to be the second most popular language, slightly behind Java. TIOBE Programming Community Index I'm curious as to why, in this age of OOP, C is ...
92 votes
10 answers
56k views

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
86 votes
22 answers
14k views

One can often hear that OOP naturally corresponds to the way people think about the world. But I would strongly disagree with this statement: We (or at least I) conceptualize the world in terms of ...
85 votes
14 answers
14k views

Does an object have to represent an entity? By an entity I mean something like a Product, Motor, a ParkingLot etc, a physical, or even a clear-cut non-physical conceptual object -- something that ...
Dennis's user avatar
  • 8,267
84 votes
6 answers
25k views

Why do many software developers violate the open/closed principle by modifying many things like renaming functions which will break the application after upgrading? This question jumps to my head ...
Anyname Donotcare's user avatar
84 votes
12 answers
31k views

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
82 votes
12 answers
53k views

I'm trying to understand the difference between procedural languages like C and object-oriented languages like C++. I've never used C++, but I've been discussing with my friends on how to ...
niko's user avatar
  • 2,119
80 votes
11 answers
20k views

Stroustrup says "Don’t immediately invent a unique base for all of your classes (an Object class). Typically, you can do better without it for many/most classes." (The C++ Programming Language Fourth ...
Matthew James Briggs's user avatar
79 votes
10 answers
45k views

Downcasting means casting from a base class (or interface) to a subclass or leaf class. An example of a downcast might be if you cast from System.Object to some other type. Downcasting is unpopular, ...
ChrisW's user avatar
  • 3,427
79 votes
10 answers
17k views

How does a functional programming language, such as Elm, achieve "No runtime exceptions"? Coming from an OOP background, runtime exceptions have been part of whatever framework that is based ...
Fireburn's user avatar
  • 889
79 votes
2 answers
13k views

Javascript is a prototype-based object oriented language but can become class-based in a variety of ways, either by: Writing the functions to be used as classes by yourself Use a nifty class system in ...
Spoike's user avatar
  • 14.8k
78 votes
14 answers
11k views

The Single Responsibility Principle states that a class should do one and only one thing. Some cases are pretty clear cut. Others, though, are difficult because what looks like "one thing" when ...
dsimcha's user avatar
  • 17.3k
76 votes
11 answers
56k views

What's the difference between the two UpdateSubject methods below? I felt using static methods is better if you just want to operate on the entities. In which situations should I go with non-static ...
Alexander's user avatar
  • 1,169
74 votes
11 answers
15k views

I have read that in OOP, we think of objects as "sending messages to each other", for example if we did car1.stop(), we say that "we sent the message stop() to the car1 object". ...
Christopher's user avatar
  • 2,049
71 votes
14 answers
6k views

In some code I'm reviewing, I'm seeing stuff that's the moral equivalent of the following: public class Foo { private Bar bar; public MethodA() { bar = new Bar(); bar.A();...
JSBձոգչ's user avatar
  • 1,440
71 votes
8 answers
21k views

Coming from a math background, counterexamples are equally, if not more, helpful to me for understanding concepts than examples. I've seen many, many examples of when and how to use the SOLID ...
Derek Allums's user avatar
67 votes
14 answers
38k views

The main idea behind OOP is to unify data and behavior in a single entity - the object. In procedural programming there is data and separately algorithms modifying the data. In the Model-View-...
Random42's user avatar
  • 10.5k
66 votes
11 answers
65k views

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
66 votes
1 answer
13k views

C++ has plain multiple inheritance, many language designs forbid it as dangerous. But some languages like Ruby and PHP use strange syntax to do the same thing and call it mixins or traits. I heard ...
Gherman's user avatar
  • 945
65 votes
8 answers
29k views

I had a very stimulating and interessting discussion with a colleague about ORM and its pros and cons. In my opinion, an ORM is useful only in the rarest cases. At least in my experience. But I don't ...
derphil's user avatar
  • 859
65 votes
12 answers
14k views

Today I had an argument with someone. I was explaining the benefits of having a rich domain model as opposed to an anemic domain model. And I demoed my point with a simple class looking like that: ...
tobiak777's user avatar
  • 807
65 votes
10 answers
36k views

Which is generally accepted practice between these two cases: function insertIntoDatabase(Account account, Otherthing thing) { database.insertMethod(account.getId(), thing.getId(), thing....
AJJ's user avatar
  • 3,048
63 votes
8 answers
29k views

I am trying to understand the SOLID principles of OOP and I've come to the conclusion that LSP and OCP have some similarities (if not to say more). the open/closed principle states "software ...
Kolyunya's user avatar
  • 975
59 votes
9 answers
23k views

This blogpost was posted on Hacker News with several upvotes. Coming from C++, most of these examples seem to go against what I've been taught. Such as example #2: Bad: def check_for_overheating(...
Pubby's user avatar
  • 3,390
59 votes
9 answers
50k views

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

1
2 3 4 5
69