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
3,433 questions
0
votes
2
answers
111
views
Should I instantiate controllers in route modules or use static methods?
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 ...
2
votes
1
answer
256
views
Is it okay to mix OOP and modular approaches when building a backend with TypeScript/JavaScript?
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 ...
2
votes
3
answers
636
views
Convenience inheritance
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 ...
5
votes
3
answers
666
views
How to get rid of Mappers and make objects build themselves?
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 ...
0
votes
2
answers
376
views
Global State, How To Do IT?
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 ...
0
votes
2
answers
156
views
Is it better to pass a specific “context” object to handlers rather than the entire domain object?
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 ...
3
votes
2
answers
264
views
How to structuring a read/write submodule in OOP Python
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 ...
2
votes
2
answers
244
views
Best way to add asynchronous execution for already implemented synchronous process
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.
...
8
votes
5
answers
4k
views
Is it still a code smell if a class knows all subtypes but not using instanceof and downcasting?
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();
}
...
3
votes
1
answer
241
views
Passing info between different branches of a class hierarchy in C++?
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....
13
votes
13
answers
3k
views
Should setters silently sanitize input — or should they just throw? [closed]
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 ...
0
votes
0
answers
107
views
Fix cyclic dependency between protocol and business classes
I'm designing a library for CANopen protocol. The basic CANopen frames are PDO and SDO, where PDO is like UDP (fire and forget) and SDO is like HTTP (request and response). A CANopen device is a PDO ...
2
votes
3
answers
324
views
How do I model this scenario so that it adheres to OOP principles?
I have a Slide class with subclasses referring to the different types of slides (IntroSlide, SummarySlide, etc.):
abstract class Slide {
String slideType;
final String title;
final String ...
3
votes
3
answers
1k
views
Should business logic classes be POJO only?
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 ...
2
votes
3
answers
434
views
What is the relationship between the terms "association", "aggregation", and "composition"?
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, ...
4
votes
5
answers
499
views
Anemic Models vs. Rich Models: When to Use?
I'm working on an application and have encountered two different approaches for organizing business logic. There's a general consensus that application rules should be handled in higher layers, so I ...
-5
votes
3
answers
262
views
Java OOP problem [closed]
I'm working on a Java programming assignment. In this assignment, there's an immutable class Book and a mutable class BookCopy. You can have multiple BookCopy of the same Book.
Now here comes the ...
0
votes
1
answer
103
views
Should domain logic reside inside or outside associated classes?
I have a question on where to put the logic in the following hypothetical:
There's this class that, at it's basis, has an int[]. There's a method that takes the int[]s of two of these classes and ...
1
vote
2
answers
299
views
OOP Design of a Mathematical Group
A Group is formally defined as a set of Element's,
over which a single operator mul is defined.
There are different kinds of Groups,
and each kind requires a different set of parameters.
Operator mul ...
0
votes
0
answers
221
views
Is "parallel composition hierarchies" a code smell?
For example, suppose I have a mobile app that uses some user data, the DTO:
class UserData{
public:
Address address;
bool isVerified=false;
};
class Address{
};
The UserData may be loaded from ...
12
votes
5
answers
4k
views
Why is "hidden dependency" (required things not in parameter list directly) a disadvantage of "global variables", but not in "preserve whole object"?
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, ...
7
votes
8
answers
5k
views
Is "avoid extra null pointer risk" a reason to avoid "introduce parameter objects"?
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,...
5
votes
4
answers
2k
views
If class B extends A, can we say that B depends on A?
Let's say we have 2 (Java) classes:
class A {}
class B extends A {}
To me, saying B extends A and B is dependent on A are both true (but not equivalent) in this situation. My colleague, OTOH, says ...
3
votes
3
answers
310
views
Handle hierarchical relationships between large number of enums
I am working on a C# project and I have a somewhat large number of labels (~100) that have some sort of relationships between one another. Here is a minimal dummy example that illustrates this:
...
2
votes
1
answer
158
views
Refactoring Processor classes
I am writing some python 3 bioinformatics software and was wondering about the best way to write it in an OOP format. I am pretty sure a lot of my classes are violating the SRP principle, but I'm not ...