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
1answer
89 views

Dynamic Object Abilities When Saving State

I have n classes that extends from a State class, the purpose of the State class is to manage the state of the extended classes. For each class we need to save it in the database, remove it and select ...
1
vote
1answer
146 views

use always get and set methods is a bad practique, is call directly an attribute class a bad practique in OOP?

I have a doubt about if there are some recommendations for call directly an attribute in a class I think that in OOP you always should call an attribute by the get method. For example: On set ...
0
votes
0answers
57 views

Apply Value Object (Stringly Typed) in PHP

What is the best way to prevent wrong states in an object? This is the source of my question. Basically my curiosity started with the intention of not letting a class exist with wrong values. Prevent ...
0
votes
3answers
231 views

Should a method decide whether to execute or not? [closed]

I couldn't find a question on SE but it has probably been asked elsewhere already (in case, please mark it). A method containing code to run just with specific external conditions can: decide ...
3
votes
2answers
124 views

How to create a tree-hierarchical structure with unique behavior for every type combination?

Assume: There is some module whose interface is IA. There is some module B, that takes in a parameter an instance of IA, and whose behavior depends upon the type of that IA, meaning (pseudo code, no ...
4
votes
1answer
207 views

Is using getters to exchange information between objects acceptable?

Suppose I have the following Character, Potion, and PotionType classes: class Player: def __init__(self, name: str, health: int, mana: int): self._name = name self._attributes: ...
0
votes
2answers
92 views

Object composition in a static function

I have a class that provides basic functionality of a modal window. For different situations I need to provide different modals(different number of buttons, titles, etc...). I have a kind of factory ...
1
vote
3answers
279 views

Is it sometimes okay to intentionally violate the Dependency Inversion Principle?

I am doing some work to refactor a class. It currently a 'God class' and contains all different logic/operations solely in that class. One of my solutions is to extract all different parts of logic to ...
-2
votes
1answer
67 views

method taking a class parameter

I have recently begun studying UML. All is going fine so far until I saw the following: This is a class Called Point2D It has 2 attributes which are x, type float and y, type float. It has 3 methods ...
-2
votes
1answer
116 views

Using static member methods to check for object being NULL

Is it a good practice to use the static member methods to check if an object of a class is NULL or not. The object would be sent through the parameters offcourse. Something like, #include <...
5
votes
1answer
424 views

How common are destructors in modern c++ code?

In the standard c++ library, all containers and all input/output streams have their own constructors and destructors, that handle all the relevant resource acquisition and release. So for most tasks ...
0
votes
0answers
147 views

Decorator Pattern Java

This is an object-oriented design question that is specific to Spring Boot. I'm extending a Spring Boot application that has an interface that is being extended and used inside another service. The ...
0
votes
2answers
156 views

ValueObject - too wordy?

So, I'm having some value objects in my domain, and when I'm using them in one of my builders it looks like this: .withSomething(Id.of(123), Specifiers.of(MySpecifier.of("233"), MySpecifier.of("23423"...
3
votes
5answers
585 views

DDD/OOP - saving Aggregates without ORM. Public getter, reflection, or injecting repository?

So for DDD folks there, Aggregate Roots are supposed to contain business logics only and exposed what is needed only. In DDD Red Book by Vaugh Vernon, he used LevelDB and Hibernate as examples. ...
12
votes
6answers
949 views

DDD meets OOP: How to implement an object-oriented repository?

A typical implementation of a DDD repository doesn't look very OO, for example a save() method: package com.example.domain; public class Product { /* public attributes for brevity */ public ...
2
votes
1answer
289 views

Does it violate GRASP if a Character class checks if it can carry a weapon?

Before I ask my question, I'm aware of Eric Lippert's Wizard and Warrior series. I'm trying to understand GRASP, but I'm having a hard time determining if this class violates GRASP. Suppose if I ...
1
vote
3answers
132 views

Should we inherit from base class and implement interface in this scenarios?

I am new to object oriented design and learning about interfaces and design patterns. In this example, I am trying to create class for cars. My question: Is it good practice to use base class and ...
6
votes
4answers
778 views

Replacing Linq Methods with Extension Methods

So, I've fallen into the fad trap, and started replacing a large amount of linq queries with extension methods. For example: orders.Where(o => o.Status == ShippedStatus.Shipped).Select(o => o....
0
votes
0answers
146 views

Role Based Access Control on OOP how do you map Permission of Role to Entity?

I've been trying to wrap my mind around this RBAC system. The goal is with a static method from a class, I can get the current user/actor, then check if he has capability to do something for specific ...
-4
votes
1answer
147 views

File structure of object-oriented projects seems cluttered [closed]

In computer science courses at University, assignments written in OO languages such as Java had file systems similar to this: TreeNode.java BinaryTree.java Assignment1.java etc. ... In writing some ...
0
votes
2answers
76 views

How to design classes of a self-driving machine, if I need a simulation?

Background: I'm working on a project with a self-driving machine with a tank-like control, somehting like: forward() left() right() stop() The code is running on a raspberry pi. The GPIO outputs are ...
0
votes
2answers
77 views

Are there any issues with having having the main data in an object's state?

class DataFrameAnnotation: def __init__(self, df: pd.DataFrame): self.df = df def transformation_1(self): self.df + 1 def transformation_2(self): self.df + 1 def main(self): ...
1
vote
1answer
95 views

Is using enums to filter attributes considered a code smell?

I was doing some reading here and one of the suggested answers states: In short: Don't try to decide how an object might react to some action from the outside, tell it what happened, and let it ...
2
votes
2answers
603 views

What are application and domain services in onion architecture?

Onion architecture has a core which is composed by domain model, domain services and application services: I'm in doubt about those two service layers, domain services and application services. I've ...
2
votes
4answers
393 views

Can method names give any implementation details and break encapsulation?

I was reading here about OOP and methods, and the accepted answer states that method names should be verbs. However, that doesn't really answer my question. Suppose if I had a Character class with a ...
2
votes
2answers
201 views

Single responsibility principle - importer

I'm writing an importer, it should fetch some data from the database and put that data into appropriate places. Now the question is, should the importer itself fetch that data, or should that data(to ...
42
votes
9answers
11k views

Is “avoid the yo-yo problem” a valid reason to allow the “primitive obsession”?

According to When is primitive obsession not a code smell?, I should create a ZipCode object to represent a zip code instead of a String object. However, in my experience, I prefer to see public ...
0
votes
0answers
53 views

Getting into situations that requires mixin while building classes. How should I correct my class design?

I have the following classes for to solve a particular problem related to HTTP responses. Problem is for class ServerSentEventStreamResponseService I am in a situation where I need mixin because I ...
0
votes
0answers
40 views

Which diagram to visualise chain of events (in Django)?

Model situation: In Django (Python web framework), I have a model Event. I need to visualize this chain of events: Everytime new Event is created, confirmation email is generated and sent to Event....
1
vote
2answers
165 views

Why are classes named “class”? [closed]

Could it also have made sense to call it a "Form", as in the Platonic sense of the ideal form that represents the thing which earthly objects strive to emulate?
6
votes
5answers
349 views

Design pattern for 2 methods one has 70% arguments of other one

I am trying to do a design for notification part in the system I have 2 parts inApp notification and email notification so I used strategy pattern where I have interface NotificationSender with one ...
1
vote
2answers
59 views

Encapsulating Permissions Logic, but looking to Avoid Circular Dependency

I'm trying to encapsulate permissions logic for a particular view model in a way that the permission logic has access to the view model object, but is also exposed inside of it Trivial Implementation:...
0
votes
5answers
214 views

Design Pattern for object that asks questions of another object

I'm looking for a design pattern that might work for this class I am working with. This main class is an entity using Domain Driven Design. public class TimeCard() : ITimeCardHeader { ...
10
votes
8answers
913 views

Is an interface exposing async functions a leaky abstraction?

I'm reading the book Dependency Injection Principles, Practices, and Patterns and I read about the concept of leaky abstraction which is well described in the book. These days I'm refactoring a C# ...
3
votes
2answers
89 views

How are settings structured when they can be configured in diffferent ways?

Suppose of this question the following: I'm in full control of this project I'm writing a media player Obviously, a media player will allow a user to adjust the volume, so I might have a class that ...
0
votes
4answers
116 views

Is there a mismatch between XSL and OOP? [closed]

context and background: I prefer OOP for the most part and find it, largely, more intuitive -- this is my bias. When I read that functional language x is better than OOP language y I think to myself:...
1
vote
2answers
544 views

DDD - Referencing Aggregate Root of other bounded context?

I'm building a personal project, as an introduction to DDD, I'm doing a little bit of analysis and can't get my head around it. My ERD looks as follows: To go over it, as an admin you can setup a ...
3
votes
2answers
223 views

Design pattern for similar classes that require different implementations

Edited: Update is at the bottom There could be a common or best practice for this scenario, but I am unfamiliar with it. However, it could very easily be a matter of subjective opinion on how one ...
-3
votes
3answers
97 views

Java - OO - Understanding Subclass of Class Object

While a fundamental concept, I don't understand the statement "every CLASS in Java is a subclass of the class object," which is often quoted in JAVA tutorials usually in the inheritance section. I ...
1
vote
2answers
105 views

Add behaviours without changing existing code

I have a data access layer, which currently communicates with a database. public interface IDao<T> // T is my DTO { Write(IEnumerable<T> dtosToPersist) } public class Dao<T> : ...
-3
votes
3answers
580 views

Object Oriented Programming what is abstraction? [duplicate]

I was hoping that someone could explain to me in the simplest way possible and with an example, what abstraction is with regards to Oop. I've read articles online and I just don't get it. I'm hoping ...
16
votes
4answers
2k views

When to move a common field into a base class?

I currently have two derived classes, A and B, that both have a field in common and I'm trying to determine if it should go up into the base class. It is never referenced from the base class, and say ...
0
votes
3answers
534 views

Interface properties implementation

As the code below, class Foo1 implements interface IFoo, which has a property of IData. public interface IFoo { public IData Data { get; set; } } public interface IData { ... } public class ...
3
votes
3answers
141 views

Does ReSharper's warning “SuggestBaseTypeForParameter” suggest design problems?

A water user can submit an Application for a water right with the hope of getting a Permit to use water, which might later become a BonaFideWaterRight. The right holder may apply to Transfer any of ...
2
votes
5answers
256 views

How do you force developers to define dependencies/arguments if it's bad to put the constructor function in the interface?

I just started reading more about OOP and its design patterns and is confused with this conceptual question. I am too new that I am having second thought that the proper title should be, "when is it ...
2
votes
2answers
44 views

Create a new class with minimal data VS. using original class and setting non-necessary data equal to 0 or null?

I am using Scala for my example but I believe this probably could apply anywhere. Say I am using a class somewhere in my project that reads in data from a live stream of events which monitors where a ...
0
votes
5answers
157 views

Data only class, other classes that read/modify it?

I have a class that only holds data, specifically Collections of data, it is called *BezierSplineData: class BezierSplineData { public List<BezierSplineControlPoint> ControlPoints; // ...
1
vote
1answer
125 views

Utils, Service class and Persistence Layer

I have a method in API handler which does API validation, performs business logic and then makes a call to db. Is it a good idea to move the business logic to utility class or service class? IMO the ...
1
vote
3answers
78 views

Class methods that are never called and everything handled by the internals of the class itself

I have a class in my code and I'm not sure if the design I've implemented is correct or if there is a better way to do it. The class I have created have important useful methods that is used by each ...
2
votes
4answers
517 views

What is a good place, in OO, to store a string that is used many places?

I have a string that is used in a few places. string portalLoginPath = $"{Request.Scheme}{Uri.SchemeDelimiter}{Request.Host}/Account/Login"; I was thinking of creating a static class with a string ...