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
0 votes
2 answers
118 views

For non-container classes, are "better naming" and "ready for commented codes" good reasons not to declare the most abstract type?

According to Why define a Java object using interface (e.g. Map) rather than implementation (HashMap), I know I should declare the most abstract type possible, but the question is about template class ...
4 votes
4 answers
3k views

Are "need to call objects in parent object" and "avoid circular dependency" reasons to avoid "Tell, don't ask"?

According to Explanation on how "Tell, Don't Ask" is considered good OO, I know I should avoid get the state of an object and then decides the actions to take to that object, eg: Bad: ...
12 votes
7 answers
10k views

Structured programming versus OO programming

I am making a presentation that shows the differences between structural and object oriented programming and I want to illustrate why people need OOP with an example where applying OOP concepts will ...
2 votes
6 answers
515 views

From the perspective of OOP, taking performance into account - should a database connection be a static field, an instance field, or a local variable?

When methods use a database connection, should the connection be a static field, an instance field, or a local variable? Here are my doubts. I dithered which are correct and which are baseless. I ...
2 votes
3 answers
5k views

What would the best way to design a giant API wrapper class with multiple 'sections'?

Here's the problem I'm trying to solve: There's a rather large API I'm trying to write a wrapper class around. The simplest approach would be to make one class with a method representing each ...
202 votes
14 answers
140k views

When are Getters and Setters Justified?

Getters and setters are often criticized as being not proper OO. On the other hand, most OO code I've seen has extensive getters and setters. When are getters and setters justified? Do you try to ...
1 vote
6 answers
311 views

How encapsulating what varies can help us?

I have a question about encapsulation and I read these two topic (this & this) but I got more confused. I've been reading Head First Object-Oriented Analysis and Design book and I'm trying to ...
4 votes
6 answers
2k views

How exactly are getters and setters defined?

Note: Questions with similar title have been asked before, but please read the full text before claiming that this is a duplicate. Since everybody in OOP uses the terms getter and setter, I would ...
2 votes
3 answers
153 views

Is it necessary or "class obsession" (opposite to primitive obsession) to create classes for non-business fields?

I know there are some posts talk about primitive obsession : When is primitive obsession not a code smell?, Is "avoid the yo-yo problem" a valid reason to allow the "primitive obsession&...
-2 votes
0 answers
55 views

Design a grading system for the institutions/Govt on an event of exam cancellation like the one happend in 2021 [closed]

can you please help me solve below object oriented design problem? basically requirement is to design classes and their interactions. It was asked to me in an interview and I was rejected in that ...
2 votes
1 answer
215 views

In poltergeist, whats wrong with "solely to trigger or initialize several other objects"? Isn't it is a good use of encapsulation and reuse?

After reading What differentiates function objects from poltergeists?, according to the definition of poltergeist, I still don't understand why would "poltergeist" be a bad pattern: A ...
7 votes
5 answers
14k views

Should I use friend classes in C++ to allow access to hidden members?

Here is my situation (a simple example). Say I have a class called HiddenData Then I have another class called StoreHiddenData And finaly a class called OperateHiddenData Here's the thing, my ...
6 votes
4 answers
6k views

When should the builder design pattern be used?

I am currently learning about various object oriented design patterns. I came across a pattern called the builder pattern which is basically where you build a complex object through the use of ...
66 votes
8 answers
13k views

When to *not* use SOLID principles

Coming from a math background, counterexamples are equally, if not more, helpful to me for understanding concepts than examples. I've seen many, many examples of when and how to use the SOLID ...
0 votes
2 answers
83 views

Where to put factories that depend on the application layer?

I am a frontend developer (currently working with Vue and TS), and I have been searching for better organization of the frontend code and recently I got to know DDD a bit. I know DDD is mostly used ...
0 votes
2 answers
68 views

How to structure a cart with cart products object

I am new to DDD and I am having trouble structuring an object. I have a cart, where I can add products to it. Each product has some properties like image, title, price, etc. Whenever a product is ...
0 votes
1 answer
65 views

REST - Adding a new field

I have an object with fields like ID, CODE, NAME, etc., and it has its own database table with each field. And I am working on implementing the REST API for this object. I want to expose all these ...
14 votes
6 answers
2k views

Clean OOP way of mapping an object to its presenter

I am creating a board game (such as chess) in Java, where each piece is its own type (like Pawn, Rook etc.). For the GUI part of the application I need an image for each of these pieces. Since doing ...
1 vote
5 answers
299 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
94 views

Logical architecture based on modules and SPI

I'm looking for the most proper way to design a modular application with ServiceLoader. --MAIN IDEA-- module app.view | exports app.view.View interface that defines UI api module app.engine | exports ...
3 votes
5 answers
617 views

Is "avoid feature envy" violating "open closed principle"?

After reading What is a" feature envy" code and why is it considered a code smell?" I know the following code is suffering from "feature envy": public class Garden{ ...
1 vote
3 answers
867 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 (...
1 vote
2 answers
73 views

MVVM: How and should I expose view models' models to other view models?

Many times while writing MVVM apps in C# I've come across this sort of problem where I need to expose the model in a view model so that I can get it in another view model and do something with it. ...
2 votes
1 answer
115 views

OO vs FP: What is a good approach to understanding if heavy wrapper classes should be used?

Consider a processing system which ingests objects from an external source and performs extensive processing. One example could be objects detected by a computer vision system which are then fed into ...
5 votes
2 answers
281 views

What is the difference between detailed design and design for construction?

I am currently reading Code Complete. And I was confused when the author in one case uses the term "detailed design", and in the other "design for construction". What is their ...
1 vote
2 answers
192 views

Composition over inheritance: how data are accessed in the composition case?

I've been reading this Wikipedia article Composition over inheritance. It gives a code example of inheritance first, and then a code example of composition. In case of inheritance there are data that ...
0 votes
1 answer
135 views

Is "Wrap child class operation into a function, then return the object, in order to declare most abstract type" necessary or over-engineering?

According to Why define a Java object using interface (e.g. Map) rather than implementation (HashMap), I should declare the most abstract type as possible. However, in some cases I remember, ...
0 votes
4 answers
238 views

Single responsibility principle - Classes with operator overload

I've been reading a bit through Clean Code and I came across the Single Responsibility Principle. The principle states that every class should have only one responsibility. An example taken from ...
17 votes
8 answers
12k views

Why is "diamond problem" a problem? Why doesn't the child simply call both parent's methods sequentially? Why is a thing with solutions a problem?

I know there have been many post about diamond problem, one of it: Why do you reduce multiple inheritance to the diamond problem?. But I'm not asking what it is or what is the solution of the problem. ...
1 vote
1 answer
59 views

Is using an UId to hash Mutable Entities an anti-pattern?

In the context of an object-oriented language, such as Dart, I have an abstract entity which has a single property called id (which is incrementally uniquely generated to make sure there are no-...
0 votes
0 answers
43 views

How to handle multiple-state domain object?

Let's take an example of Order. An order can have the state new, canceled, shipped, or processing. The new order can be processed. The new order can be canceled. The processing order can be shipped. ...
14 votes
3 answers
4k views

How do you approach class design in OOPs?

When I try to design an OO solution ,I generally use the CRC modelling wherein I list the class names (nouns), what they do(verbs) and how they collaborate with other classes. This blog has the below ...
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: ...
2 votes
1 answer
184 views

Domain models: Can they be an abstract class

When talking about having a rich domain model successfully, in real applications, it needs to, somehow, access some abstraction of complex functionality (instead of being a row state calculator the ...
1 vote
1 answer
355 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 ...
0 votes
1 answer
66 views

Creating Controllers and Repositories without corresponding Models

I have to create a system to interview people on a few topics where they have to answer both objective and discursive questions, where questions may change between interviews. I structured the ...
0 votes
1 answer
241 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 ...
0 votes
1 answer
150 views

Clean architecture - how to manage use cases that depends on external apis

How to apply clean architecture concepts in a software that depends on External APIs. Example: A business that offers some kind of subscription to its users. Its convinient to store some subscription ...
0 votes
1 answer
156 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 ...
6 votes
2 answers
32k views

Are Spring beans declared as static a poor design choice?

The question is pretty straightforward, I'll try to explain why I want some explanations. (All of this is my 1½-year junior Java developer opinion, which may be more than incomplete. Which is why I ...
0 votes
1 answer
73 views

Mapping list to another list dynamically

I had an idea for a piece of software using .NET C# as technology. Basically, in my idea Im thinking of using reflection to do the mapping between a class to another class using interactivity with a ...
0 votes
0 answers
46 views

Should I add new method to the interface to use it more commonly or just separate the new logic completely

I have a CouponReservationService in an e-commerce project. It is called when a coupon is reserved to be applied to a basket. It checks that whether the coupons are already reserved. If they are ...
3 votes
9 answers
604 views

Can a Domain Object always be "completely ignorant of persistence" and yet still possible to persist?

Domain Object, while not necessarily a design pattern, can at least be considered as a design "concept", and one of its points is: https://wiki.c2.com/?DomainObject Domain objects should ...
13 votes
3 answers
3k views

Applying SOLID principles

I am quite new to the S.O.L.I.D. design principles. I understand their cause and benefits, but yet i fail to apply them to a smaller project which I want to refactor as a practical exercise to use the ...
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 ...
11 votes
3 answers
4k views

Is there any point in using builders and fluid interfaces with object initialisers?

In Java and C#, you can create an object with properties that can be set at initialisation by either defining a constructor with parameters, defining each property after constructing the object, or ...
1 vote
2 answers
193 views

Is "declaring most abstract type" suffers from the same problem as "primitive obsession"?

According to Why define a Java object using interface (e.g. Map) rather than implementation (HashMap), when creating objects, I should declare the most abstract type, eg : Map hashMap=new HashMap(). ...
1 vote
3 answers
636 views

Architecture for slot machine game

I am building a slot machine game for a client (virtual money, not real-money gambling). They started out with a template game and hired me to reskin it and make "minor" changes for a "...
111 votes
13 answers
61k views

Why is C not considered an 'object-oriented' language?

It seems that C has its own quasi-objects such as 'structs' that can be considered as objects (in the high-level way that we would normally think). And also, C files themselves are basically separate ...
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) ...

1
2 3 4 5
67