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
3answers
156 views

What behaviours to put in and out of a class

Let's say I have a class modeling some kind of object, for example a graph (in the graph theory sense). I will have the graph structure and data inside the class, but what about other more complex ...
4
votes
2answers
154 views

Should I use classes instead of functions with a state needed for computation?

I have implemented the cows and bulls game in C++. The code: #include <cstdio> #include <cstdlib> #include <ctime> struct DigitMatches { int matches_in_right_positions; int ...
0
votes
2answers
90 views

What is the best practice for temporarily pairing an attribute with a class

Consider a case, in which a class needs an attribute only in a very limited context. (For example, only during initialization, which is handled by a factory) I do not want to include such an attribute ...
3
votes
2answers
54 views

Accessing properties from embedded objects as atributes of container class

In Python, I have a class C which embeds objects from classes A and B. Is it considered good practice to creates shortcuts from the properties of embeddded objects of classes A and B as attributes of ...
0
votes
0answers
47 views

Is Controller a special kind of Indirection in GRASP Design pattern?

This is Indirection according to Wikipedia Assign the responsibility to an intermediate object to mediate between other components or services so that they are not directly coupled. Controller seems ...
-4
votes
1answer
67 views

How to use DRY methods with OS commands with Python and classes

My goal is to learn more about OOP patterns and use DRY principles. I am trying this for wrapping an os command that interacts with a database using classes: This works fine: import subprocess class ...
0
votes
1answer
71 views

Different Aggregate Root States in Domain Driven Design

I have read the Domain Modeling Made Functional book. In the book, the author model the Order in 3 different states: Unvalidated Validated Priced The 3 states have different properties. But it's ...
0
votes
1answer
87 views

Time consideration in multiplicity of classes

In the following image, regarding a CD shop that rents its music CDs. My question is regarding the correct multiplicity of X. I can think of several possibilities for X: X= 1..1 as each copy of ...
-1
votes
1answer
107 views

conversion methods: from_xxx() or to_xxx(), is there a reason I shouldn't stick with to_xxx()?

I have a C++ library that I'm converting to python. In the C++ library I have multiple constructors and many different types of conversion functions (think radians to degrees, and different types of ...
0
votes
1answer
46 views

Best mapping practices in an enterprise application

This question might seem like a trivial question. But here it goes. Currently, I'm working with this .NET Core application, an N-tier application consisting of a Vue frontend, business logic layer, ...
0
votes
3answers
203 views

Is it a code smell to have a static factory method on the base class?

Suppose we have a BaseModel, which has a type enum, and derived models with same constructor signatures to each other, whose implementations are like : public DerivedModelJ(Object arg1, ..., Object ...
0
votes
3answers
148 views

When should I create a base class and subclasses that work similarly, as opposed to a single class?

So, a situation's come up at work today while refactoring my codebase. I have two classes that each derive from the same base class. The only significant difference between them is what they do at the ...
0
votes
2answers
145 views

How best to deal with growing polymorphic interfaces?

Consider the following scenario in an object-oriented environment. Sample code is in C++, but it could be any OO language. A software must control an external device, say a TV. From the start you know ...
0
votes
2answers
57 views

How to implement resources of a REST API as classes?

I need to access and process different resources from a REST API. For this I've come up with two different approaches: Approach 1: Create one class per resource, that handles accessing the data from ...
2
votes
3answers
200 views

What we called this design pattern and it is same as strategy pattern?

abstract class BaseService { public void doSomething(); } class AService extends BaseService { public void doSomething(){ // Do something... } } class BService extends BaseService { ...
2
votes
5answers
479 views

Class method Vs. Interface?

I am relatively new to C# and OOP concepts in general, but am building a standalone application and have run into a question and want to make sure I'm doing it the "right way". I have a few ...
0
votes
0answers
56 views

State Pattern: Changing object behavior based on more than one field and consistency between their values and state value

I'm Trying to learn about State Pattern. In most of State Pattern examples that I have seen, methods of class change their behavior based on just one field (I mean before applying State Pattern and I'...
0
votes
3answers
112 views

What should be the optimal management of end user messages in N-tier architecture?

I'm curious about your thoughts on this subject that we have discussed with the people around me. Especially at the architectural stage, in which layer is the most optimal and efficient way to use the ...
-2
votes
1answer
71 views

Having multiple classes that share the same instance variables for context consistency

I am wondering if it is an acceptable approach to pass instance variables from one object to an object of another class (saving them as instance variables as well) in order to retain the context that ...
2
votes
2answers
185 views

Is "pass through" boilerplate code the trade off for improved encapsulation and composition?

Is it a sign that something is wrong with the code design if you end up with a layer of functions that just forward request to a component? Exposing the component would avoid this but hurts ...
3
votes
4answers
269 views

Single Responsibility Principle, Inheritance

I have the following interface: class IHittable { virtual Intersections intersects(const Ray & ray) = 0 } which will be implemented by various geometric objects(Spheres, Triangles etc). Now ...
2
votes
2answers
76 views

Modeling combination of two independent abstractions

I am building an app (.NET, but whatever) which is supposed to be able to send notifications to users. Each Notification can either be a Reminder or a Newsletter, and I'll possibly add more types in ...
1
vote
2answers
47 views

Getters and (static) processor vs multiple processor wrappers

I've got a class which stores two data series like so. I need to do some complicated processing on each of these arrays, but for now we'll just get the average of each data series. I could either do ...
-2
votes
2answers
72 views

Feature branches vs controller extension

Note: Controller here refers to one from MVCs Bear with me, I know these are seemingly unrelated. However, I'm inclined to think both are analogous to each other being that they're means to the same ...
-2
votes
2answers
180 views

OOP: How to Manipulate Objects Using ORM Techniques?

about those objects and arraylists inside the classes, derived from one-to-many relationships, using the ORM techniques, what's the best way to deal with them at the time of setters and validation ...
1
vote
3answers
130 views

Extracting interface or use double dispatch to avoid downcasting?

Here's an analogy of our concrete problem to demonstrate the issue at hand. We need to manufacture cars, with either petrol or diesel related parts (the parts can be the engine and the exhaust - e.g. ...
1
vote
3answers
234 views

How to use abstract factory on interacting widgets

Context In many GUI frameworks, it is very common that widgets are placed in a container to arrange them visually in a window. For example, in Gtkmm, a window with a label and a button (side by side) ...
1
vote
2answers
126 views

Model updating itself in MVC?

My group in school is tasked with creating an application of our own choosing which follows good object oriented design principles. The group has chosen to make a tower defense game with help of ...
3
votes
2answers
118 views

Getting the UI to know about Business Rules for Form Controls

Situation: VB.NET WinForms application, using the WinForms as a presentation layer project. Another class library project containing the business layer, in the form of CQS and Service classes, plus a ...
0
votes
3answers
90 views

Handling Objects with Same Output but different required inputs

I have various types of financial securities. Each one of these securities shares a common set of methods. For instance, they all pay some amount of cash interest between two dates. Each security has ...
8
votes
3answers
908 views

The Liskov Substitution Principle, and Python

Background I've taught myself Python over the past year-and-a-bit, and would consider myself an intermediate Python user at this point, but never studied computing at school/university. As such, my ...
3
votes
4answers
419 views

If other objects can modify an attribute, is it truly private?

I am working in Python so attribute privacy isn't enforced. I have a Library class that stores a list of library Items related to that library. I want to be able to access the library Items through ...
0
votes
2answers
126 views

How to enforce matching, but unknown interfaces

I am challenging my OO design skills and started an ambitious project that is supposed to be highly reusable and extensible. It is supposed to be kind of a framework for evolutionary algorithms. Maybe ...
0
votes
4answers
141 views

Is casting between interfaces the best approach for capability discovery when using interface inheritance?

It’s frequently taught that downcasting is bad practice. I have a case where it seems necessary, but I’m wondering if there is an alternative way to design this. Suppose interfaces are kept small ...
0
votes
1answer
95 views

How should I provide access to "global" objects down to other objects which are contained in a central "application" object

Note This is a bit lengthy to have give a better understanding of the situation and to get some context. You might spot other architectural flaws (it's from an ancient application). I appreciate any ...
2
votes
3answers
221 views

Definition of static property of object in OOP

Grady Booch in Object-Oriented Analysis and Design with Applications says: The state of an object encompasses all of the (usually static) properties of the object plus the current (usually dynamic) ...
-1
votes
2answers
138 views

Implementation of method differs only in one line

I have 2 implementation of the interface: public interface MyInterface{ void getCollectedData(MyData mydata); } public class MyImpl implements MyInterface{ public void getCollectedData(MyData ...
1
vote
1answer
144 views

C# how to implement a factory class which doesn't require an argument passed to indicate objects type?

I currently working on a parser project in C# and have run into problem. I have an entity folder within my project and within it I have: Entity IEntity.cs (defines a contract for entity classes) ...
1
vote
6answers
220 views

Liskov Substitution Principle Inconsistency? How to figure out?

Liskov Substitution Principle states: "if S is a subtype of T, then objects of type T may be replaced with objects of type S without altering any of the desirable properties of the program (...
-1
votes
1answer
82 views

Adapter pattern for formatting third party API responses

I've been refactoring some of my procedural code to OOP, and I'm wondering if using the adapter pattern is overkill in this case. Basically, I created a Order class. All class properties are a field ...
3
votes
2answers
257 views

How to use visitor pattern when objects change frequently

It is said that visitor pattern is applicable to problems where objects rarely change but we add actions on those objects more frequently. What if the objects are changing too though? For example we ...
0
votes
1answer
112 views

Abstract Base Class decides which type of child class to create at runtime

I have an Abstract Base Class AbstractModel class AbstractModel { public: struct predictionStructure{}; virtual predictionStructure predict(CompanyLib::Matrix<double> data) = 0; std::...
1
vote
3answers
187 views

Clean architecture, Login UseCase with OAuth breaking Single responsability principle

I'm building a login system using OAuth to integrate with various social networks. The flow is very simple, first, the user is redirected to their social network to grant permission to read the ...
22
votes
11answers
4k views

In a fluent interface with "with", is cloning expected?

In an object oriented language like Java or PHP (other perspectives welcome as well) if I use a fluent interface like this: my_pizza = (new Pizza).withTopping("pineapple"); another_pizza = ...
1
vote
2answers
57 views

How to properly implement Rest Controllers to handle overlapping entities?

I have: A User entity. A Poll entity. Relationship: User creates polls. Use-case: When an arbitrarily user is clicked his/her profile is loaded and shown. The profile includes a list of polls ...
1
vote
2answers
359 views

Are experienced developers and software architects able to describe an entire software application in terms of design patterns?

Do experienced developers and software architects see entire application in terms of design patterns? In other words experienced developers and software architects able to describe an entire software ...
0
votes
1answer
96 views

Should I define a separate interface for clarity rather than implementing Supplier<T>?

Let's say you have to meet some prerequisites before doing something. For that, I think implementing Supplier<Boolean> is a great candidate since it's widely used, and quick to understand. But, ...
1
vote
1answer
84 views

How to implement Gang of Four's Lexi's Compositor-Composition?

I'm studying Design Patterns book and I was trying to understand the Composition principle in Lexi's Compositor-Composition as explained in figure 2.5, as well as how to implement it. Where the ...
-2
votes
1answer
168 views

Why aren't constructors atomic? [closed]

If thrown exceptions in constructors can lead to memory leaks or partially-constructed objects, then why we don't make them atomic? so neither an object nor it's local variables will get created/...
1
vote
1answer
737 views

Low-level Design of a Bike Rental Service

I'm working on the low-level design of a bike rental service and I was wondering if the solution is good or where it can be improved. Context & Requirements I used an exercise I found online which ...

1
2 3 4 5
64