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 vote
2 answers
371 views

Is it okay to extend more than one class if a new type/feature is needed?

I coudn't find a better phrasing for my question and hope it is not too confusing. my question mainly targets the open/closed principle and extensibility of my program. I tried to condense everything ...
lorenz albert's user avatar
0 votes
1 answer
658 views

DDD - How to avoid validation rule duplication

From what I understand of DDD, my entities and value objects should be able to enforce its own invariants, meaning that its constructors will check for nulls, must contains numbers and letters, ...
Douglas Monteiro's user avatar
0 votes
2 answers
82 views

Where to specify UI views in a hierarchy of model objects?

In a Flutter app I'm developing, I have a class hierarchy of model objects of a certain base class. To take a typical example, the abstract base class could be Vehicle. Then I have a (pretty much) ...
Anakhand's user avatar
  • 177
2 votes
1 answer
272 views

How to restrict the construction of a domain object to an external service?

I have this object RelativeFoo{int relativeCode, Origin relativeTo} And I want to map it to this other object AbsoluteFoo{int absoluteCode} In order to do this, I need to use a service whose ...
Douglas Monteiro's user avatar
0 votes
2 answers
271 views

How to create an interface in C that can work on two identical structs with differently named fields

Question Background Consider a scenario in which I have two structs. Both consist of three fields for doubles. The only difference is the names used to refer to these fields. The first struct is for ...
Shadow43375's user avatar
2 votes
2 answers
170 views

Explain forbidden inheritance across the domain dimensions of representation/implementation vs semantics

I am going through this nice write up on thoughtworks about inheritance vs composition. I understood the authors explanation of the dual purpose of inheritance. But, I am confused on the specific ...
kosa's user avatar
  • 159
1 vote
3 answers
248 views

Is this really loosely coupled?

I was going through the source code of an existing project and totally confused about one implementation. The project is created in .Net 6 and it's a frontend MVC project. It's part of a microservice ...
Optimus's user avatar
  • 111
8 votes
4 answers
714 views

Is inheriting from a non-abstract class bad OOP?

I read a talk entitled "Deep C (and C++)" by Olve Maudal and Jon Jagger. I paste the relevant code and quote below, but here is the link to the slides. On slide 349, the presenters show this ...
Eoin's user avatar
  • 309
1 vote
1 answer
155 views

Can I separate methods into different classes by passing in constructor properties from one class to another?

I am making a game of monopoly. Inside my game I have a Board class. The Board class has an array which contains 40 squares. Each square is a different class e.g. ChanceSquare, PropertySquare ...
Kevin Greetham's user avatar
0 votes
2 answers
154 views

Is there a UML symbol representing instantiation? This one doesn't seem to be one

The following figure comes from https://spring.io/guides/topicals/spring-security-architecture I refer to it as a "figure" rather than a "diagram" as I'm not sure if it is. the ...
JJJohn's user avatar
  • 111
15 votes
6 answers
6k views

Why can't a mutable interface/class inherit from an immutable one?

I've heard people say things like "B can't inherit from A because A is immutable and B is mutable". My understanding of inheritance in Object-Oriented Programming is that you use it to add ...
GlenPeterson's user avatar
  • 14.9k
5 votes
4 answers
313 views

Does my outer class adhere to the Single Responsibility Principle?

I often write front end apps with a generic MVC pattern. I use javascript but this questions is language independent and relates to OOP as a whole. I struggle to understand the SRP principle and I ...
Kevin Greetham's user avatar
1 vote
1 answer
893 views

onion architecture - calling external APIs

Umbrella Question In an onion architecture, where do all the components needed to consume an external API fit in? The following is the architecture I have so far, based off an example found here: ...
dot's user avatar
  • 531
1 vote
2 answers
135 views

physical simulation: design thoughts

I'm an applied physics student and currently working on a simulation of the magnetic interactions of multiple protons within a protein. Me having only little experience with programming and almost ...
Meck3l's user avatar
  • 17
-1 votes
2 answers
160 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 ...
multigoodverse's user avatar
2 votes
0 answers
72 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. ...
tim's user avatar
  • 131
-2 votes
1 answer
142 views

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

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 ...
Dennis's user avatar
  • 19
0 votes
2 answers
254 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 ...
Ayush Kumar's user avatar
0 votes
0 answers
34 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 ...
RobbyG's user avatar
  • 101
0 votes
1 answer
316 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 ...
Kevin Greetham's user avatar
1 vote
1 answer
165 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 ...
tntenigma's user avatar
0 votes
1 answer
430 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 ...
Kee's user avatar
  • 13
1 vote
0 answers
327 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 ...
Janilson's user avatar
  • 121
1 vote
3 answers
109 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, ...
Simone Brigante's user avatar
1 vote
3 answers
1k 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 ...
BeeFriedman's user avatar
0 votes
3 answers
574 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 ...
Zed's user avatar
  • 117
3 votes
4 answers
776 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 ...
Tinker's user avatar
  • 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 ...
J. Mini's user avatar
  • 997
3 votes
2 answers
809 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 ...
Ced's user avatar
  • 285
1 vote
3 answers
714 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 ...
66Gramms's user avatar
  • 129
0 votes
2 answers
874 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 ...
charmoniumQ's user avatar
28 votes
3 answers
9k 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 ...
Bondolin's user avatar
  • 393
3 votes
4 answers
248 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 ...
user6490576's user avatar
3 votes
3 answers
340 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, ...
Treker's user avatar
  • 151
0 votes
2 answers
158 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 ...
Happy Coder's user avatar
0 votes
2 answers
239 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. ...
Gullit's user avatar
  • 13
0 votes
2 answers
555 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 ...
Robin Kreuzer's user avatar
2 votes
2 answers
190 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 ...
Dennis's user avatar
  • 8,157
2 votes
2 answers
134 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: ...
aarnaut's user avatar
  • 259
2 votes
3 answers
239 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 ...
dbrewster's user avatar
  • 139
0 votes
3 answers
261 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, ...
Yoh's user avatar
  • 51
2 votes
3 answers
294 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, ...
ThePunisher's user avatar
0 votes
1 answer
252 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 ...
user16405900's user avatar
9 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 ...
Stefan Rendevski's user avatar
-3 votes
1 answer
131 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 ...
Ali's user avatar
  • 15
3 votes
3 answers
217 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'...
Tim Kirkwood's user avatar
2 votes
1 answer
88 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 ...
ErikE's user avatar
  • 1,151
0 votes
2 answers
152 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(...
Chryfi's user avatar
  • 129
0 votes
1 answer
200 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: ...
Martin Gonzalez's user avatar
2 votes
2 answers
296 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 = ...
redcurry's user avatar
  • 133

1
2
3 4 5
67