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
2 votes
4 answers
124 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 ...
2 votes
2 answers
89 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 ...
0 votes
2 answers
158 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 ...
1 vote
3 answers
187 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 ...
-3 votes
0 answers
53 views

how to manage versioning in software design? [closed]

I am new in this platform, as well in my new job. I have been asked to design, describe and provide a software documentation to the developers. this software should be managed by an admin user. this ...
27 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 ...
-1 votes
0 answers
51 views

Best way to read object's data from a store that is used many times

I have a class called Field. While it is being created it's getting an id and then it must read its name from a store. public class Field { private readonly Guid _id; public Field(Guid id) ...
3 votes
4 answers
225 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
257 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, ...
0 votes
2 answers
133 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 ...
2 votes
3 answers
5k views

Extending a struct. Using helper classes rather than composition

I have a struct which I want to add static methods to. Yes, you guessed right I'm talking about Datetime. It's a pretty typical requirement to add MyCustomParse. It happens to return Datetime?, so it'...
0 votes
3 answers
205 views

Specialization and LSP violation?

I have Document and ExternalDocument classes in my system, where ExternalDocument extends Document. The main distinction is that ExternalDocument holds onto externalDocumentId and externalEventId data ...
0 votes
2 answers
168 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. ...
0 votes
2 answers
82 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 ...
1 vote
3 answers
741 views

Safety of magic setters in PHP

I don't know how in else languages, but in PHP seems to me that they are very unsafe way how to set value of any member variable - because one setter cannot easily validate input for many variables (...
16 votes
6 answers
3k views

What is a precise issue with allowing getters?

I am not looking for an opinion about semantics but simply for a case where having getters sensibly used is an actual impediment. Maybe it throws me into a never-ending spiral of relying on them, ...
2 votes
2 answers
125 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 ...
7 votes
5 answers
2k views

Why do some of object oriented languages let programmer use primitive types?

Why do some object oriented languages let the programmer use primitive data types? Aren't classes like Integer, Boolean, etc. enough?
2 votes
5 answers
401 views

Should methods always be closed for modification?

Say I have a method called 'functionA' that is called by a service and carries out a single piece of functionality, it is easy to unit test as it is does one thing only. If a few months later an new ...
2 votes
2 answers
123 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: ...
0 votes
1 answer
91 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 ...
49 votes
9 answers
13k views

Return considered harmful? Can code be functional without it?

OK, so the title is a little clickbaity but seriously I've been on a tell, don't ask (TDA) kick for a while. I like how it encourages methods to be used as messages in true object-oriented fashion. ...
2 votes
3 answers
149 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 ...
10 votes
4 answers
3k views

Why not apply Interface Segregation Principle to "extreme"

Providing that clients would typically consume just one method, though methods would be conceptually related, why not always apply the Interface Segregation Principle to the extreme and have [many] ...
18 votes
3 answers
2k views

Is there a term for over-complication of OOP?

A year or two ago I saw an excellent article on OOP (Java), which showed the progression of a simple concrete logger of two or three lines of code, and a theoretical excessive thought processes by the ...
0 votes
3 answers
179 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, ...
4 votes
3 answers
121 views

Using Multiple 'Sub-types' vs a larger single type?

I have a user model in an application that I'm working on, which currently uses sub-types to encapsulate properties depending on what type of user you are - I just can't help but think that this is ...
-3 votes
3 answers
262 views

OOP and class that inherit from many classes

In OOP, is it possible to have a class that inherits from multiple other classes? And if yes, how is this situation called? For example, suppose I have the following classes: Eye Nose Mouth Eyebrow ...
1 vote
1 answer
180 views

Check if a controller is doing too many things

There is REST endpoint in my application which handles POST request and then makes a HTTP post to another external application and when the resource is creating in the external resource then I create ...
18 votes
11 answers
10k views

Need Good OOP Design For World and Countries Problem

I am currently working on problem with a chicken or egg first situation. Basically, I am designing a solution which goes like this: World is a collection of countries; Each Country has a name, flag ...
28 votes
4 answers
4k views

Law of Demeter and over-wide interfaces

The Law of Demeter makes sense in some obvious cases. # better dog.walk() # worse dog.legs().front().left().move() dog.legs().back().right().move() # etc. But in other cases it seems to lead to an ...
2 votes
3 answers
235 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
94 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: ...
0 votes
1 answer
794 views

The finer points of HMVC

I'm new to HMVC and whilst tutorials are great about dealing with the overall details of keeping modules separate and only letting controllers communicate, they aren't so great at explaining the ...
3 votes
3 answers
2k views

Design pattern to force client of a class to call a method

I have a large class with complex properties. I'd like to introduce a default implementation, allow the user to override part of the default implementation and also make sure the user calls a sync ...
1 vote
1 answer
301 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 ...
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 ...
6 votes
3 answers
803 views

Persistent Model to Domain Model mapping without exposing domain object's attributes

I know this is a common question, but I haven't found another that solves my doubts. Usually, if the project is small, I've persistence annotations in the same object that represents the domain ...
-3 votes
1 answer
106 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 ...
0 votes
1 answer
188 views

Could this be considered a valid State GoF Pattern implementation?

For teaching purpose, I would like to create a simple implementation of State Pattern using PHP 7.4. So, I've tried to create a simple "document state machine" starting with Draft, sending to review ...
3 votes
3 answers
134 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'...
2 votes
1 answer
82 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 ...
0 votes
1 answer
134 views

Using the objects retrieved at the time of request validation

I hope the question title already answers the subject here. Lets say I have a number of ids that needs to be validated in a request. Example: request uri: [POST] /album/{album_id}/song Request ...
0 votes
0 answers
39 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'...
2 votes
4 answers
1k views

How to deal with recursive dependencies in OO languages?

2022 Disclaimer: I asked this question when I was novice. It is bad. There are two major mistakes I did : some of the names given are really bad, because in production code, when you name something ...
8 votes
4 answers
4k views

Why are public and private accessors considered good practice? [duplicate]

Possible Duplicate: When are Getters and Setters Justified Why exactly is having public and private accessors like these: private string foo; public string Foo { get { return ...
21 votes
5 answers
123k views

What is the use of Association, Aggregation and Composition?

I have gone through lots of theories about what is encapsulation and the three techniques of implementing it, which are Association, Aggregation and Composition. What I found is: Encapsulation ...
0 votes
2 answers
97 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(...
2 votes
2 answers
257 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 = ...
5 votes
2 answers
707 views

Polymorphism and the potential security issues

I just read an article on MSDN about reasons for declaring classes as sealed. In the last paragraph, Eric Lippert says: 4) Secure. the whole point of polymorphism is that you can pass around ...

1
2 3 4 5
66