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
26 questions from the last 365 days
0
votes
2
answers
112
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 ...
0
votes
2
answers
190
views
How to reduce the number of class instances passed to the __init__() method of a Python class?
I have a Python class called FunctionsManager; its __init__() method is the following:
class FunctionsManager:
def __init__(self, instance_class1, instance_class2, ..., instance_classN):
...
2
votes
1
answer
261
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 ...
1
vote
1
answer
257
views
OO design - Process that relies on the current state of objects
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, ...
2
votes
3
answers
670
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 ...
-1
votes
1
answer
144
views
How to organize struct-based "methods" in C similar to object-oriented style? [closed]
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.
...
5
votes
3
answers
667
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 ...
3
votes
6
answers
609
views
Is OOP really beneficial for enterprise-scale business software compared to procedural languages like ABAP or COBOL?
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 ...
0
votes
2
answers
377
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 ...
4
votes
2
answers
2k
views
Should I expose an instance's state with methods?
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 (...
0
votes
2
answers
160
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 ...
1
vote
1
answer
119
views
When does encapsulating a primitive field into its own class make sense? [duplicate]
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 ...
4
votes
2
answers
267
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 ...
3
votes
7
answers
565
views
Do I need to create an interface for every service class to follow good design principles?
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,...
2
votes
2
answers
251
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.
...
6
votes
7
answers
721
views
Why do "protected variables" tend to violate open closed principle?
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 ...
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();
}
...
2
votes
1
answer
234
views
Extracting type info
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++ ...
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....
4
votes
1
answer
297
views
Refactoring a codebase from manual memory management to RAII
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 ...
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 ...
1
vote
3
answers
519
views
C# var vs. interface vs. concrete class in object instantiation
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 ...
0
votes
0
answers
108
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
1
answer
200
views
Is widening parameter types in a PHP interface implementation a good practice?
I have an interface defined as follows:
interface MyInterface
{
public function setMyMethod(int $a);
public function getMyMethod(): int;
}
And I have a class that widens the parameter type:
...
2
votes
3
answers
325
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 ...
17
votes
5
answers
3k
views
Should parameter names describe their object type?
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(...