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
2 votes
3 answers
669 views

Sometimes, you inherit from a class that defines the semantics of your type (Shape – Ellipse – Circle). Other times, you inherit simply because it's convenient to do so. A superclass may have ...
Sergey Zolotarev's user avatar
0 votes
2 answers
112 views

I’m building a modular REST API using Node.js + Express + TypeScript. My controllers are defined as classes. In my route files, I currently create a new controller instance, like this: import { Router ...
dok's user avatar
  • 313
2 votes
1 answer
261 views

I’m designing a backend in TypeScript (could also apply to JavaScript), and I’m wondering about the architectural approach. Is it better to stick to a single paradigm (e.g., fully object-oriented or ...
dok's user avatar
  • 313
0 votes
2 answers
190 views

I have a Python class called FunctionsManager; its __init__() method is the following: class FunctionsManager: def __init__(self, instance_class1, instance_class2, ..., instance_classN): ...
User051209's user avatar
1 vote
1 answer
257 views

We have a CAD software extension, where you can draw products like walls, doors, windows, etc., and you can export the drawing as an order, which contains the parts and costs. As part of this export, ...
Divan's user avatar
  • 369
24 votes
16 answers
19k views

A getter is a failure to design an object. It violates encapsulation which is a core principle of object oriented programing. Now please tell me, how do you design a libraries hash table collection ...
candied_orange's user avatar
8 votes
5 answers
4k views

According to Instanceof code smell, I know using "instanceof" is a code smell, so suppose there is a game with some Tools: Tool.java: public interface Tool{ public void printInfo(); } ...
wcminipgasker2023's user avatar
3 votes
6 answers
609 views

I'm currently drafting a Python coding standard for internal enterprise use, primarily targeting business applications that involve heavy data access, reporting, and transactional logic. In this ...
agolta's user avatar
  • 77
17 votes
5 answers
3k views

I'm unsure whether parameter names should describe their object types or if shorter, more concise names are preferable. Consider the following two method signatures: public void PrintPoint(...
Abcd's user avatar
  • 297
13 votes
13 answers
3k views

Suppose the code's inside some FullName class And suppose I want only capitalized name elements (let's ignore the fact that in some cultures, name elements may start with a lower-case letter) Should I ...
Sergey Zolotarev's user avatar
5 votes
3 answers
667 views

I am having a really hard time deciding where to instantiate my entities in the refactoring I am making. The project was built with DDD and it's layered: it has the infra, domain and app layers. In ...
Bernardo Benini Fantin's user avatar
4 votes
2 answers
2k views

I've read somewhere about a pattern that is as follows: if it'll change the state of the instance, the method should be named with a verb and return void; and if the method just returns something (...
Bernardo Benini Fantin's user avatar
29 votes
14 answers
11k views

I'm a junior in my company, and one of the coding rules they have is: "a constructor object must never fail" (i.e., never throw). So what if I give them an invalid parameter? Then, the ...
sayanel's user avatar
  • 509
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
6 votes
7 answers
721 views

According to Why is Clean Code suggesting avoiding protected variables?, I know there are tons of reasons to avoid protected variables. However, there is a reason at the currently highest voted answer ...
wcminipgasker2023's user avatar
-1 votes
1 answer
144 views

So I was coding in C for a while now, getting used to language syntax and different styles. Implemented a couple of simple data structures, algorithms and tried my skills in making Minesweeper clone. ...
MightyBeast's user avatar
3 votes
7 answers
565 views

I'm working on a custom Magento 2 module in my internship, and I'm trying to follow SOLID principles in my code. Right now, my controller actions handle everything: getting request data, processing it,...
Ruben Eekhof's user avatar
0 votes
2 answers
377 views

im kind of a newbie so take me easy i face a problem every time i make a project specially Client projects, which is Global State i always struggle to do it for example, here is the structure of one ...
PythoonNoob9000's user avatar
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
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
4 votes
2 answers
267 views

I am developing a python package that needs to be able to read/write from/to multiple formats. E.g. foo format and bar format. I am trying to contain the functions relating to each format in a single ...
Luce's user avatar
  • 149
25 votes
10 answers
10k views

If you have an OO language, where every object always has a copy method, shouldn't that be deep copy by default? In most languages I know, such a copy method is shallow, since a shallow copy is more ...
Mecki's user avatar
  • 2,390
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
7 votes
8 answers
5k views

According to Should we avoid custom objects as parameters?, I know I can group related parameters to improve readability of the function, eg: Original version: public void showSchedule(long startDate,...
wcminipgasker2023's user avatar
12 votes
5 answers
4k views

According to https://softwareengineering.stackexchange.com/a/200092, as I know, "preserve whole object" is a refactor method that passes the whole object instead of required parameters only, ...
wcminipgasker2023's user avatar
13 votes
6 answers
10k views

Suppose we have an Instance class in a C++ program, which has a GUID/UUID, name, parents, children, and other properties which can be saved to or loaded from an XML file. The intuitive approach for ...
Bunabyte's user avatar
  • 657
18 votes
8 answers
14k views

I know there have been many post about diamond problem, one of it: Why do you reduce multiple inheritance to the diamond problem?. But I'm not asking what it is or what is the solution of the problem. ...
wcminipgasker2023's user avatar
15 votes
9 answers
6k views

Note: I'm not looking for opinions on whether the authors of the article below are right or wrong. Mainly I'm looking for the exact definition of what they mean by getters, especially since I know ...
Ced's user avatar
  • 609
0 votes
2 answers
160 views

I’m designing a system where various “handlers” apply business rules to an object. Initially I had each handler receive the full domain object: // A large domain object with many properties and ...
nicke7117's user avatar
5 votes
11 answers
2k views

According to When is primitive obsession not a code smell? and answer in https://softwareengineering.stackexchange.com/a/365205, I know one of the advantages of avoiding primitive obsession is "...
wcminipgasker2023's user avatar
2 votes
2 answers
251 views

I have a complex process implemented in Java Spring microservice. Currently this process is triggered on user request and it is synchronously executed. This often results in a gateway timeout. ...
DimitrijeCiric's user avatar
1 vote
3 answers
519 views

As we know, there are (at least) four ways to instantiate a class object in C#. But I've never quite understood why some ways are better than others. First of all, you can explicitly declare the ...
Cade Bryant's user avatar
2 votes
3 answers
444 views

I try to brush up on my technical interview skills as I plan to seek a better offer I don't recall being ever asked that really, but I still want to clear up any confusion. What is association, ...
Sergey Zolotarev's user avatar
1 vote
1 answer
119 views

Let's say I have the following Java code: public record Person(String firtName, String lastName, int age) {} Can it makes sense to have instead: public record Person(FirstName firtName, LastName ...
Nyamiou The Galeanthrope's user avatar
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
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 ...
3 votes
5 answers
812 views

According to Why should I use dependency injection?, "dependency injection" has some advantages, for example: "Non dependency injection" version: public class Client{ private ...
wcminipgasker2023's user avatar
14 votes
5 answers
5k views

According to Explanation on how "Tell, Don't Ask" is considered good OO, I know the following is bad: if(a.isX){ a.doY(); } public class A{ public boolean isX; public void ...
wcminipgasker2023's user avatar
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
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
2 votes
1 answer
234 views

Suppose that I want to implement the following scenario. There is a board and each board has a set of peripherals like leds, temp sensors, gpio and so on. Each of them implements the according C++ ...
bielu000's user avatar
  • 351
3 votes
1 answer
241 views

So, I have a class hierarchy that looks like this: It is an embedded project, so the entire code will be run over and over. I have several algorithm classes, that compute some result given some inputs....
Rares Dima's user avatar
3 votes
3 answers
1k views

I read about three-tier architecture and I have a question: I read that in business logic (that is, what is in logic tier) there should be POJO classes, but in most Spring manuals these classes are ...
dude34810's user avatar
4 votes
1 answer
297 views

Edit: @Ben Cottrell's comment said this was similar to a question about spaghetti code. While both questions involve large codebases, mine addresses a specific technical pattern: manual memory ...
Arno's user avatar
  • 151
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
1 vote
4 answers
1k views

I know you can't inherit static methods, and it seems the consensus is that if you feel like you need to, you're doing something wrong. However, I don't know what the alternative is in my case. Please ...
Andrew's user avatar
  • 21
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 ...
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
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
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

1
2 3 4 5
69