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
-1 votes
2 answers
122 views

Should I make a HotelList class?

This question has always bothered me I am finally ready to ask it out here. I am creating a hotel reservation app, and I am in the phase of deciding what classes I will have. Among classes such as ...
2 votes
0 answers
37 views

Factory based on input type

I'm trying to add specialized functionality to concrete types without adding the functionality directly to the interface of those concrete types. Given a vehicle interface with 3 concrete types. ...
  • 121
-3 votes
1 answer
70 views

Which paradigm(between OOP and Functional) should be chosen for a given task? [closed]

Which paradigm(between OOP and Functional) should be chosen for a given task ? What are the tradeoffs between these two styles ? In which case using Functional makes sense and vice versa,in which case ...
  • 9
0 votes
2 answers
214 views

How is my class breaking encapsulation?

I was submitting this code in Java to an AI tool that checks for OOPS modeling and it says that this class is breaking encapsulation, although it did not gave any reason why. The objective is to store ...
0 votes
0 answers
32 views

If I have Object b of Class B inside Object a of Class A, which class should contain methods relating to manipulating data in Object b? [duplicate]

I have written some code that contains the class Game and the class Draft. Inside of Game I have a private member, instance of Draft draft. When a user requests through the UI, a game must return some ...
  • 101
0 votes
1 answer
77 views

Is this a good example of what a service layer is in MVC?

I am wondering what a service layer is in MVC. I like to understand concepts through a game of monopoly as it's relatable to a lot of people and fairly easy to explain whilst allowing for some good ...
1 vote
1 answer
95 views

Representing database tables as objects

I'm building an address book API, where a user can input multiple contact names, phone numbers, and addresses. My database structure would be as follows: create table user ( id int not null primary ...
0 votes
1 answer
86 views

Pattern to convert different types of similar unchangeable objects to the same object

I have an existing system that inserts books into a library database, and I want to generalize it to include other media. The other media is similar, but not exactly the same, and all media are third ...
  • 13
0 votes
0 answers
72 views

Avoiding forward declaration and circular reference in C++

Consider a card game (something like Magic or Legends of Runeterra) program, with BaseCard, Deck and GameState classes/structs. The way I've conceptualized the relationship between these classes would ...
  • 111
1 vote
3 answers
70 views

Separating network logic from business logic

I am creating a simple P2P file sharing system, where one peer can send some Objects (e.g., String, custom objects, etc...) to another peer. The peer, that receives the Object, can then manipulate it, ...
1 vote
3 answers
343 views

When Should I Use a Static Class and When Should I Just Use Functions?

I am currently building a C# application that gets JSON data then it calculates something then stores the results in a database, what is the proper way to design the application. This is how it's now ...
0 votes
2 answers
139 views

How to handle a new method in the interface that is not applicable for all classes?

I am faced with an interesting OOD problem: I have an interface with 3 methods: interface TestInterface { String action1(); String action2(); String action3(); } and 3 classes that ...
  • 109
3 votes
4 answers
303 views

Should I implement one interface with two methods or two interfaces?

NOTE: This question is reposted from SO because it violates community guidelines for being opinion-based. I have two classes that are similar in nature but they have different functional signatures. I ...
  • 155
38 votes
10 answers
9k views

Why do heavily object-oriented languages avoid having functions as a primitive type?

As has been covered to the point of parody, heavily object-oriented languages, such as C# or Java, tend to lack the feature of having functions as a primitive type. You can argue about whether or not ...
  • 763
3 votes
2 answers
225 views

In the OO DDD , does the domain object access the repository directly?

I'm reading OO DDD slides from Robert Brautigam, who is quite active here so I hope he can personally answer as I quite agree with his personal understanding of DDD, and approach of having a more ...
  • 276
1 vote
3 answers
222 views

Const function that change other objects' states

Is it a good idea to mark a function const from clean code perspective if it change other objects' states? I'd like to know what is the experience with this or is it considered a bad practice for any ...
  • 119
0 votes
2 answers
188 views

What are the considerations between a class variable and a global variable

At first glance, these seem equivalent. If one has the right visibility, one can access a global variable or a class variable from anywhere in the program; There is only one, shared copy of them. So ...
28 votes
3 answers
8k views

Is it Good Practice to Only Expose Interfaces

I''m working on a C# library where the API provides several public interfaces and a single concrete factory class (itself an interface implementation). This factory provides implementations of the ...
  • 393
3 votes
4 answers
241 views

Does it make sense to use the word 'Set' in a class as an umbrella term for both sets and individual items?

For instance, if I'm modeling a book collection and I want to be able to represent sets of books that come together (like an encyclopedia series), the sets may share a lot of properties that ...
3 votes
3 answers
272 views

Large Inheritance Hierarchy vs. One Object With Many Nullable Fields

I am working on implementing some stock order types for a financial technology application. There are six different types of stock orders - market, limit, stop_loss, stop_loss_limit, trailing_stop, ...
  • 151
0 votes
2 answers
137 views

Refactor to object oriented style and use design patterns

I have an application that has been written in Python and it is used for generating various MIS reports for a specified month. It is now written without using the OOPs concepts or any kind of design ...
0 votes
2 answers
189 views

Coffee machine strategy pattern implementation

I came across an article about LSP https://stackify.com/solid-design-liskov-substitution-principle/ . It seems that a strategy pattern could be implemented here but I cannot see how to implement it. ...
  • 13
0 votes
2 answers
129 views

Inheritance/Composition VS "Direct Injection Construction"

my following example seems to go into the direction Inheritance VS Composition. But that's not, what i want to ask. I see the concept Inheritance and Composition on one side and the alternative, which ...
2 votes
2 answers
141 views

To maintain SOLID, should data preparation, conversion, and pre-computation for purposes of saving an object, be separate from data persistence layer?

I am facing a common situation where I am saving some values into database from a business object. I am using a relational database and usually I only need to save a few items that are part of the ...
  • 8,049
2 votes
2 answers
127 views

Should you pass an instance of service to a model class?

Say we have these view model classes. You can imagine there's an entry in the UI for each subtype of InfoItem, and each item contains some text and an icon. abstract class InfoItem(text: String, icon: ...
  • 249
2 votes
3 answers
167 views

how to leverage overloading while keeping business logic out of models

I am running into a conflict between two best practice principles- overloading should be used instead of long chained if/else statements models should not contain business logic I am working on a ...
  • 139
0 votes
3 answers
182 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, ...
  • 51
2 votes
3 answers
242 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, ...
0 votes
1 answer
103 views

Best way to name derived classes when extending its functionality [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. Rather than ...
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 ...
-3 votes
1 answer
115 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 ...
  • 15
3 votes
3 answers
146 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'...
0 votes
0 answers
54 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'...
  • 149
2 votes
1 answer
83 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 ...
  • 1,151
0 votes
2 answers
99 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(...
  • 29
0 votes
1 answer
98 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: ...
2 votes
2 answers
259 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 = ...
  • 133
1 vote
3 answers
188 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. ...
3 votes
4 answers
450 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 ...
1 vote
1 answer
166 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 ...
0 votes
1 answer
188 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 ...
-1 votes
1 answer
401 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 ...
-1 votes
2 answers
269 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 ...
  • 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 ...
1 vote
1 answer
133 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 ...
  • 119
0 votes
0 answers
57 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 ...
0 votes
2 answers
122 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 ...
  • 329
0 votes
2 answers
224 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 ...
1 vote
0 answers
387 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, ...
  • 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 ...

1
2 3 4 5
66