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
-3 votes
0 answers
38 views

Should I really be breaking my big methods up into smaller ones? [duplicate]

I was taught in CS classes to break big methods up into smaller ones as a blanket rule, but I am finding myself more and more with these programs that are made up of one method that just calls a bunch ...
user avatar
0 votes
3 answers
166 views

How to handle subclasses needing different method signatures for the overriden function?

I have an abstract class that represents chess pieces, it has an abstract method isMoveValid(Square futurePosition, PieceColor color) which checks if the piece moving to that square is valid or not, ...
user avatar
  • 27
2 votes
3 answers
206 views

Object Oriented Programming - what is the best way to add new parameters?

I have a doubt about what would be the right OOP approach for implementing classes that do similar stuff with different parameters. To provide a simple example, I would use two polynomial classes, ...
user avatar
0 votes
1 answer
71 views

Best Way to name derived classes when extending its functionality C# [closed]

I have just recently joined a new company and One of the classes used to log information has not been written properly. So i have been asked to add new functionality to the logger. So rather than ...
user avatar
8 votes
4 answers
2k views

UnsupportedOperationException vs Interface Segregation

This is a follow up/related question to a previous question I asked regarding Interface Segregation. I'll build up on the same example, providing a bit more context. In the game I'm developing, a card ...
user avatar
-3 votes
1 answer
95 views

What is the importance of "this" pointer in cpp? [closed]

I apologize for asking this intuitive question. I'm not good at programming and my recent work requires me to work a lot with SDEs. I wonder what might be the advantages using the this pointer? I ...
user avatar
  • 15
2 votes
3 answers
114 views

Referencing transient class attributes

I've just started dipping my feet into OOP. Is it considered bad practice to have classes that reference attributes that depend on another function being called and thus may not exist (version 1)? I'...
user avatar
0 votes
0 answers
33 views

Dispatch based on ENUM/String value

I've the following classes: TypeAHandler, TypeBHandler,... Each handler can turnOn or turnOff a list of object ids (e.g. handler for type A calls microservice, handler for Type B modifies DB entry). I'...
user avatar
  • 149
2 votes
1 answer
79 views

Best way to manage shared state in parent-child objects where children need to check other children

Is there a best practice for managing shared state between a parent and child objects that is most likely to avoid bugs, maintain consistency, and be easy to implement/understand and maintain? As a ...
user avatar
  • 1,151
0 votes
2 answers
93 views

When using composition when to favour wrapper methods?

When using composition, when should we favour wrapper methods? Let's say we have the classic car example. public class Car { private Battery battery; //wrapper method public void load(...
user avatar
  • 29
0 votes
1 answer
92 views

Validation in a simple DDD example

I'm doing a simple project that represents a CI Pipeline in a low scale. So I'm trying to model "the best way possible" to practice DDD. Basically I have the following information: ...
user avatar
2 votes
2 answers
248 views

How to come up with an easy-to-use way of creating quantities with units in C#?

I want to come up with a way to make it easy to write classes that represent quantities with units, such as length, weight, etc. For example, var height = new Length(32.2, LengthUnit.M); var weight = ...
user avatar
  • 133
1 vote
3 answers
171 views

Class design: should I split responsibilities or should the class take care of itself?

I have a Curve class that has some CurveData inside as private member as well as getter functions for topics of interest (e.g. peaks, width and so). So the math logic of a curve is inside this class. ...
user avatar
3 votes
4 answers
429 views

If encapsulation and abstraction is so important, why do we care about how things work "under the hood"

As I am learning OOP principles, I know that it is always good practice to hide the inner workings of classes so that the end user can't access or break them. I understand why this is important. The ...
user avatar
1 vote
1 answer
154 views

Polymorphism: Overriding properties versus overwriting attributes

In polymorphism, your base class defines an interface. The inheriting classes fill in the data for that interface. The key is that the interface remains the same. Given that, if your interface is ...
user avatar
0 votes
1 answer
68 views

Dependency Injection for dynamic objects

I am learning about Dependency Injection and I have been recently implementing the following classes for an app that executes commands over ssh using Python. I am confused about whether I am using it ...
user avatar
-1 votes
1 answer
74 views

Calling helper functions in a Python `__init__` function

Problem I am currently working with a class that necessarily has a very complicated initialization function (>350 lines of code) given that many computations and attributes need to be performed and ...
user avatar
-1 votes
2 answers
242 views

Is it bad practice to have too many direct subclasses?

Let's say we have an undo/redo system and we have a superclass storing an object that should later form a tree of the attributes that can be undone/redone. This would require every class that should ...
user avatar
  • 29
5 votes
3 answers
2k views

Looking for the name for an abstract class that models functions as objects

In mathematics, adding two functions can be considered an operation in the space of functions. The result is another function. I can model this by making functions an abstract class and implement all ...
user avatar
1 vote
1 answer
120 views

What to name class that applies methods of another class?

This is a pretty vague question, but, sometimes, I'm not very good at naming specific tasks, but I know it's very important and I don't want to name it something ungood. I have the following file ...
user avatar
  • 119
0 votes
0 answers
49 views

parent-child properties value inheritance at runtime/instance

I have 2 entities with a parent-child relation (like a base product and product variants), basically the two entities have the same properties and at runtime (when instantiating the object) if the the ...
user avatar
0 votes
2 answers
89 views

Should I instantiate the state objects of a finite state machine?

I have a class hierarchy with a base State class, several inheriting classes each named after their relevant state, and an FSM class that contains all the states in a particular state machine as well ...
user avatar
  • 329
0 votes
2 answers
82 views

DDD: Where to place a service that transform data our of the domain

I am new on DDD and hexagonal architecture and I am stuck in deciding where to place a very simple piece of code. To code is a simple JWT decode. For SRP reasons, I want to isolate this action into an ...
user avatar
1 vote
0 answers
176 views

Best way to store key-value pairs of different types in c++?

I'm reading values from a (PE) binary file. The values have a known length and position in the file and are stored with no padding (right next to each other). They store various types (int, long, ...
user avatar
  • 111
9 votes
3 answers
2k views

Why is having bloated interfaces an anti pattern?

[I'm using the term interface here with C#'s interface in mind. I won't tag the question with a C# tag because it really isn't a C# question.] In my work we do unit and integration tests but we don't ...
user avatar
-3 votes
1 answer
97 views

How would a SRP `class Car` look like? [closed]

SRP insists that a class should have only a single a reason to change. Please guide me through the following example. class Car { drive_forward(); embark(); disembark(); fuel_up(); } ...
user avatar
  • 6,745
0 votes
0 answers
56 views

When does it make sense to have an implicit contract between a runtime env. and an internally used library?

┌────────────────────────────────────────────────────────────────────────────────────────────────────┐ │ ...
user avatar
  • 101
0 votes
1 answer
174 views

Clean code and SOLID principles in WPF/MVVM view models?

I'm currently reading "Clean Code" by Robert Martin (which I should have read years ago), and it's given me a bit of a wakeup call, especially regarding keeping methods and classes small, ...
user avatar
1 vote
2 answers
90 views

How to deduplicate implementation details coupling to the host objects' actions?

I came upon a situation where multiple classes manifest duplicated logic. They all delegate to a worker object, but when interrupted they have to stop the worker. class A { Worker w; public ...
user avatar
  • 33
0 votes
0 answers
62 views

Splitting an object's state into multiple objects

I'm writing a virtual CPU, and I decided to create a class for each command, to make it easier to replace/add/remove commands without changing too much. The original idea was that ICommand would be ...
user avatar
0 votes
1 answer
99 views

Correct way to deduplicate conditional statements [closed]

I'm facing with problem that in every function (with serves as service for endpoint) I need to check what is value of query parameter (mode). I need to check it on many callables, E.g. def create(self,...
user avatar
  • 111
-1 votes
2 answers
115 views

Do I really need TaskManager class? [duplicate]

Background: I'm coding an app, the core idea is simple - I can choose a 'Task' (consists of name, code to perform aka Runnable, progress) through GUI, start it, stop it, start all 'Task's and stop all ...
user avatar
  • 33
14 votes
11 answers
5k views

Encapsulation dilemma: should age operations depend on external dates outside the object?

A few days ago I stumbled upon a silly "problem" that made me reflect about encapsulation and OOP design. I have a class called User that has a method hasMinimumLegalAge() that checks if the ...
user avatar
1 vote
2 answers
164 views

Should an entity know how to render itself or is it renderers job to figure out how to draw an Entity?

If I have a graph which consists of nodes like this: class Graph { public: ... int32_t width(); int32_t height(); const Node * getNode(int32_t height, int32_t width)...
user avatar
  • 161
1 vote
1 answer
132 views

Free standing functions usable for Base pointers

I read multiple times that when a member function only uses API of class it is member of, then it should be made free standing and put in to same namespace, for example, bad practice: namespace A { ...
user avatar
  • 161
31 votes
9 answers
7k views

Is extracting an interface just for testing purposes a code smell?

I will explain with an hypothetical example. Suppose that my domain is Cars. Everyone around the software, talks about cars. Car is the aggregate root of aggregate roots. For example, CAR table has ...
user avatar
  • 705
0 votes
0 answers
27 views

Modeling a predicate/criteria builder

For a project I am currently doing, I am supposed to build a way to express "rules" about a certain system in a database and then be able to check if entities fulfill this ruleset or not. ...
user avatar
0 votes
1 answer
123 views

How are Object Oriented Databases represented?

I have read many articles online but each one of them fail to give even a basic example on how an Object Oriented Database is stored and represented. For example each of the articles say that they are ...
user avatar
0 votes
1 answer
122 views

Changing the generic type when chaining operations

I have a class where I want to chain certain operations. The class look something like this class MyClass<T> { create<X>(fn: (_: T) => X): MyClass<X> { ... ...
user avatar
  • 119
2 votes
3 answers
222 views

Is there any redundancy within the scope of SOLID principles?

I have read in an article DIP in the Wild that "When Robert Martin first discussed the DIP, he equated it a first-class combination of the Open Closed Principle and the Liskov Substitution ...
user avatar
  • 101
2 votes
1 answer
369 views

Difference between `Class.X` and `Class.getX()`?

Might be a silly question or something I might have just messed up in my head but here we go... I saw a code example of someone using getPos() in their own class to retrieve the current position of an ...
user avatar
3 votes
5 answers
278 views

Add specific behavior inside classes

I'm learning to make games with OOP and there's something I don't understand. What I can see is that the more I add methods to a class, the less it becomes reusable and flexible. For example, if we ...
user avatar
1 vote
0 answers
137 views

What design pattern does this implementation follow?

For a middleware solution I expose an API, which processes data and sends the necessary information to different parties. In the current design we create a new client, which acts sort of like an ...
user avatar
-1 votes
1 answer
91 views

Is an object with a single method Run() ok? [closed]

In my design i have a lot of objects which have a single Run() method, which when called performs what the object should do. Is that a valid interface design? It seems as though most objects I ...
user avatar
2 votes
2 answers
316 views

How to handle duplicate null checks

I'm working with a legacy codebase that has a lot of functions with a nullcheck on the same object. Example: std::vector<SessionNode*> * SessionManager::SessionMap; Session * getSession(int ...
user avatar
49 votes
7 answers
9k views

Why is inheritance bad in a Person-Student model?

I've just started learning about Inheritance vs Composition and it's kind of tricky for me to get my head around it for some reason. I have these classes: Person class Person { public string Name {...
user avatar
1 vote
0 answers
50 views

Create Views depending on the dynamic type of an object returned by the model in MVP

In my MVP app, my model (a service) returns a collection of ISession pointers. Each pointer points to an object of a derived type HttpSession or HttpsSession. The model (the service) knows nothing ...
user avatar
  • 111
2 votes
3 answers
227 views

Should classes with business logic inherit from a class with helper methods, or vise-versa?

I have a codebase where some classes contain both "essential" business logic, and "incidental" complexity. I am considering a refactor where I leverage inheritance to improve the ...
user avatar
  • 195
1 vote
2 answers
131 views

Should I add functionality by adding a new method to a class - or should I "register" the new functionality into a data structure?

I have one large class that computes ~50 different metrics (each metric has no side effects). My code is similar to this: class ReportingMetrics: def __init__(self, data:pd.DataFrame, config:dict)...
user avatar
  • 195
0 votes
0 answers
48 views

Application of dependency inversion principle in designing tree

I'm currently refreshing my knowledge of Scala with Coursera Course Functional Programming Principles. In one of the assignment there is TreeSet structure designed like that: abstract class TweetSet ...
user avatar

1
2 3 4 5
65