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
1 answer
60 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,705
0 votes
0 answers
55 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
100 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
-3 votes
0 answers
70 views

Utilizing OOP principles effectively to implement a graph algorithms demo application

I am currently working on writing a C++ app whose purpose it is to essentially "demo" various graph algorithms. At the moment, I have a very bare-bones Graph class working (which utilizes ...
user avatar
1 vote
2 answers
88 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
51 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
92 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
110 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
  • 35
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
158 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
128 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
  • 695
0 votes
0 answers
25 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
121 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
120 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
201 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
367 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
274 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
132 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
87 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
302 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
45 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
170 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
129 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
41 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 vote
1 answer
34 views

Register a collection of tested object and get one configuraton out of it

I have a yml configuration file that list multiple application. Each application can contain multiple configuration. And of course each configuration can contain multiple mode apps: - name: foo ...
user avatar
  • 149
1 vote
2 answers
113 views

How to maintain cohesion, loose coupling, and SRP when building a reporting tool?

I'm building a reporting tool with three core layers: Extract data from a database Transform this data to compute business metrics Display these metrics in a report (a heavily formatted Excel export ...
user avatar
  • 119
2 votes
4 answers
229 views

What is the middle ground between understanding basic OOP concepts (inheritance, composition, aggregation) and design/architectural patterns?

I've been coding in python for about 6 years now. I am proficient enough to understand a good amount of the language features. When I look into source code for a number of libraries such as pandas or ...
user avatar
  • 213
-1 votes
2 answers
114 views

Is having a big class always considered bad OOP design? [closed]

So I have this distributed game im working on(for some time now). A part of the world is considered a Chunk object. This object is composed of many other objects/components that are necessary and a ...
user avatar
  • 7
1 vote
1 answer
87 views

Constructor initializer list too bloated?

I noticed that my Member initializer list is not really readable. My main.cpp files looks like this: #include "Application.hpp" using Pathfinding::Core::Application; int main() { ...
user avatar
  • 161
2 votes
1 answer
127 views

Delegating whole class bad practice?

Suppose I have the following struct: struct Dimension { void setDimension(Vector2i dim); Vector2i getDimension() const; bool canShowInformation(); } And this struct uses the Dimension ...
user avatar
  • 161
1 vote
1 answer
143 views

How to test around a giant static class?

I am dealing with an old .net code base which has a PrivilegeChecker static class with hundreds of static methods, each of which takes in some user id and some other params, and then fetches some info ...
user avatar
  • 196
3 votes
4 answers
356 views

(How) can the circle-ellipse problem be solved by using composition rather than inheritance?

I was reading about composition over inheritance and came across a question about solving the Circle-Ellipse Problem in Object-Oriented Programming. This kind of problem is often used as an example of ...
user avatar
  • 147
0 votes
2 answers
161 views

Share data between users without a database, php [closed]

How would I create for example a live chat, where you "post" a piece of text and it is displayed to other users in a "chat room", without the need of permanently storing it. My ...
user avatar
  • 23
2 votes
2 answers
205 views

How could I extend these methods that use flexible arguments?

Context Let's say I have a Shape class (I'll use C# for the code snippets) that represents a 2D shape, like a triangle or a circle. These shapes have an area, so I'll include a method for calculating ...
user avatar
5 votes
3 answers
216 views

Better to store references to an object, or to store its ID and retrieve it with a hashMap

Given the classes: public class SocialNetwork { private final Map<String, User> users; ... } public class User { private final String user; private final LinkedList<String>...
user avatar
  • 61
1 vote
1 answer
105 views

Sharing business validation cross Vertical Slices

I’m doing an task based application using Vertical Slice Architecture (VSA) and domain driven design (DDD). Tasks split into commands and queries and using Mediator pattern. Say I’m having an Order ...
user avatar
  • 111
1 vote
1 answer
280 views

MVC-like architecture: Model-Controller communication of results/status

I'm struggling on designing a solid architecture for my project. In particular, I don't know how to handle the communication between the models and the controllers. My goals are: Following the ...
user avatar
2 votes
2 answers
117 views

Procedural configuration code to object oriented code

Lets say we have an Webserver-Framework and a Database-Framework, and now i want to configure that Webserver and the Database, then it could look like the following class Start { public static ...
user avatar
0 votes
3 answers
118 views

UpCasting DownCasting vs HighLevel modules/LowLevel modules

I am confused with wording used to describe UpCasting/DownCasting compared to wording used to describe level of modules. Imagine two classes: public class Human { } public class Doctor : Human { } ...
user avatar
  • 21
1 vote
2 answers
210 views

Java - Is this a good use case of Java object optimization?

I recently joined a new project that is written in java. The project has been worked on for a few years by different developers, so there are many different code styles across different classes, and ...
user avatar
2 votes
3 answers
229 views

OOPS Relationship between Soccer Field and Soccer Player

I am trying to design a simple Soccer game. To keep things simple, I am having a SoccerField to represent the field and a Player class to represent an individual. A SoccerField will contain a list of ...
user avatar
2 votes
3 answers
326 views

How do you achieve encapsulation while "separating view and business logic"?

I've been trying to get a better understanding of OOP (I'm not the biggest fan of it, but I still want to understand it). One of the core principles of OOP is encapsulation - you're supposed to ...
user avatar
1 vote
3 answers
213 views

What behaviours to put in and out of a class

Let's say I have a class modeling some kind of object, for example a graph (in the graph theory sense). I will have the graph structure and data inside the class, but what about other more complex ...
user avatar
4 votes
2 answers
250 views

Should I use classes instead of functions with a state needed for computation?

I have implemented the cows and bulls game in C++. The code: #include <cstdio> #include <cstdlib> #include <ctime> struct DigitMatches { int matches_in_right_positions; int ...
user avatar
  • 51
0 votes
2 answers
103 views

What is the best practice for temporarily pairing an attribute with a class

Consider a case, in which a class needs an attribute only in a very limited context. (For example, only during initialization, which is handled by a factory) I do not want to include such an attribute ...
user avatar
3 votes
2 answers
89 views

Accessing properties from embedded objects as attributes of container class

In Python, I have a class C which embeds objects from classes A and B. Is it considered good practice to creates shortcuts from the properties of embedded objects of classes A and B as attributes of ...
user avatar
0 votes
0 answers
74 views

Is Controller a special kind of Indirection in GRASP Design pattern?

This is Indirection according to Wikipedia Assign the responsibility to an intermediate object to mediate between other components or services so that they are not directly coupled. Controller seems ...
user avatar
-4 votes
1 answer
70 views

How to use DRY methods with OS commands with Python and classes

My goal is to learn more about OOP patterns and use DRY principles. I am trying this for wrapping an os command that interacts with a database using classes: This works fine: import subprocess class ...
user avatar

1
2 3 4 5
65