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
7
votes
4answers
678 views

Changing States from child through parent while obeying SOLID principles

I'm trying to practise following SOLID principles. I'm a bit puzzled about following example (which is a remodel/artificial example based on actual code, which i cannot post here): public class ...
1
vote
1answer
242 views

What can I do to make adding new concrete classes (of abstract/interface classes) easier across the code base?

A real (but simplified) example from the program that I'm currently working on. We have an abstract Request class and two classes that extend it: FooRequest and BarRequest. They both have dao's used ...
4
votes
2answers
283 views

C# How to combine types I don't have access to?

I have been developing a library with the help of another library. So what I have set up here is two classes sub-classing the library's classes for additional functionality. The problem comes in when ...
2
votes
1answer
133 views

OOP: Interface design when having objects embedded in parent classes

During the design of a small app I ended up with two possible design alternatives that both would work but, somehow, I feel one could be better than the other in terms of following OOP Principles, ...
1
vote
2answers
141 views

OO Design - Encapsulation question

Scenario Let's say that there is an entity in my domain called Shop. As a shop owner (user), I am able to create rewards that customer users will be able to exchange. It also could be possible to have ...
1
vote
2answers
88 views

Creational design pattern that allows configuration of objects

With the factory pattern we abstract the creation of objects. But what if we need a specific configuration of an object that depends on the calling context? Example: So I have a Builder pattern for ...
3
votes
4answers
301 views

Design an entity with multiple representations (depending on the context / use-case)

Scenario Let's say there is a Shop entity in my app. And two types of users: a Customer and an Admin. When a customer buys anything at a shop, that customer's visit is registered in the system (there'...
0
votes
1answer
156 views

Object oriented parsing: Is there a pattern or is my approach wrong?

The problem that I am chewing on comes from parsing, i.e. constructing objects in a sequential manner. The grammar is not prefix free, that is, there are more than one syntactical elements sharing the ...
0
votes
3answers
158 views

How do you enforce rules for the members of a collection in a non-OOP way?

When everything seems to be a collection, how do you enforce rules for members of said collection without the use of an interface? As far as I am aware, in languages that don't fully support OOP ...
1
vote
3answers
372 views

Is it good practice to make everything internal in C#?

In our solution we have a couple of projects, a project for data layer, service layer, business layer. etc. Inside the business layer, we use models to transfer data from classes to classes. Is it ...
1
vote
1answer
150 views

Domain Driven Design - Bi Directional association between aggregates

I've been struggling with modeling something out correctly, the DDD way. The use case is quite simple. You're a User, and you can be part of a Group. So we have a 1 - many between group and users ( ...
0
votes
2answers
66 views

Module with globals or Class with attributes?

Currently I'm working with a lot of modules where the original developers used global variables to control states and to exchange important information between functions, like so: STATE_VAR = 0 def ...
0
votes
2answers
719 views

How to separate data and logic to achieve Single Responsibility Principle in C# way? [duplicate]

I'm still learning C# and best practices around it. Consider this block of code public class Counter { private int _value = 0; public void SetValue(int x) { _value = x; // ...
9
votes
4answers
1k views

Can renaming a method preserve encapsulation?

I was reading this page, about when getters/setters are justified, and the OP gave the following code sample: class Fridge { int cheese; void set_cheese(int _cheese) { cheese = _cheese; } ...
0
votes
0answers
61 views

Clean OOP and efficient GPU buffers: not possible without data duplication? [duplicate]

I'm working on research about rendering of very large models, where the frame-rate goal is not the usual 60FPS for game design, but instead, the goal is to achieve an "interactive enough" frame-rate (...
7
votes
3answers
475 views

Avoiding side effects in immutable class constructor

I rewrote a very long method in which some data is queried from a database, based on info about a particular account, which is queried first. I split out the account info into an immutable inner ...
1
vote
2answers
193 views

Declaring an object that extends a class and implements more than one interface

I'm confused about how should I declare an object that implements more than one interface, or derives from a class that implements one interface, and implements another interface itself. Let's ...
1
vote
2answers
99 views

How to manage item locations in an inventory

I have to manage item locations and life cycle as a new requirement. I'm not familiar in warehousing/inventory/storage systems, so maybe my question is trivial. The task: We have original items that ...
0
votes
2answers
262 views

C++ tactics / data structures / design patterns to avoid or postpone unnecessary object creation?

A couple of months ago I wrote a C++ program for computational mathematics that was supposed to compete with a highly optimized C code. After a while I did manage to get it fast enough to beat the C ...
2
votes
6answers
121 views

How can I change my code to display information about failure of creation of a value object, when I want to process an array of such objects?

Consider class Crate that is a value object. Crate represents a valid 3-dimensional box. In constructor I validate the given parameters, and I throw an exception, if supplied dimension parameters ...
3
votes
2answers
280 views

Does my class violate the Single Responsibility Principle in SOLID?

I want to ask: Whether the Role class violates Single Responsibility Principle in SOLID ? I think deleteAccount() is not belong to Role class but Role class is way to extend code in the future ...
2
votes
3answers
248 views

Object Oriented Design - Genome Class / Mutation Class

Context I am having an argument with my friend on how to start implementing a Genetic Algorithm called NEAT (NeuroEvolution of Augmenting Topologies). Method 1 I am arguing in favor of having two ...
1
vote
2answers
117 views

Does is break SRP to keep incompatible physical units and quantities together in the same class, where quantities describe an object?

I want to design a Crate object. A crate is a wooden box that stores things. I need to be able to keep track of of the following things in regards to this crate: length in inches width in inches ...
0
votes
2answers
145 views

Temporal coupling vs. complex constructor

I'm working through a book on writing Single Page Applications in Vanilla Javascript. (I'm working on a project where I'm not allowed to use React or any other frameworks, so I'm trying to get better ...
2
votes
1answer
95 views

Designing Models from complex ERP SQL tables

I have a project coming up where I'm supposed to upgrade an existing access app to a .net architecture. I'm wondering how to design object-oriented models from the giant tables and multiple ...
2
votes
4answers
768 views

Instanceof code smell

The use of instanceof might be a code smell and I am in front of the following code which seems ok. Would you consider that instanceof should not be used in such case? What would be the pattern to use?...
3
votes
4answers
415 views

OOP - Is this data hiding?

I've been reading about data hiding and there seem to be slightly different definitions of it, so when trying to come up with a practical example, I'm not sure if I'm doing the right thing. So far, I ...
-1
votes
1answer
70 views

Which programming paradigm mixes well with reactive in java? [closed]

So I have the feeling that one can forget object oriented programming when reactive streams are in use, due to the lack of the async-await syntax (because with the call chaining, the state has to be ...
0
votes
1answer
98 views

Refactoring – Removing switch statement [duplicate]

There is a base class Product having all the generic properties and methods which a product should have. abstract class Product { public abstract function process(); } Now, These are the few ...
1
vote
2answers
155 views

Representing a recursive Structure in OOP

I want to represent an Edifact message in an OOP Language. An Edifact message has the following structure: message := [ ( segment | segmentgroup ) ] segmentgroup : = [ ( segment | segmentgroup )...
3
votes
1answer
143 views

C++ pattern for compile-time configurable class functionality

Due to resource limitations (embedded), I want to make some functionality that a class provides optional. The decision to include this optional functionality should be made at compile time. For ...
6
votes
8answers
808 views

How to apply OOP to real world examples without putting all logic in Manager classes?

I'm lately trying to implement a specific problem using an object-oriented approach. I get the main principles and its advantages, but I fail to apply it to a real world problem. Most examples one ...
3
votes
0answers
88 views

What's the use of interfaces vs classes in typescript?

In the company in which I work, it is customary to model entities using Interfaces when developing with Typescript. To me, it seems much more effective to model entities with classes and then ...
0
votes
1answer
148 views

c# Fluent Builder and invalid object state

I have a question about Fluent Interface Builder. I have a simple object like this: public class Person { public string Name { get; set; } public string Surname { get; set; } public int ...
1
vote
1answer
163 views

Do complex return types in interfaces exist in programming?

I believe, for PHP, that I've found the worst culprit when it comes to bad code: not being able to declare (return) implementation details through interfaces. This makes it unpredictable to see what ...
1
vote
3answers
500 views

Why shouldn't I create a class for every property?

In a particular program I had written, I noticed I had a few classes with this pattern: class IdObject: '''Objects with generated id properties''' def __init__(self, id_generator): ...
1
vote
1answer
98 views

Classes with lots of injected dependencies [closed]

I'm often finding that my classes end up with many (10-15) dependencies being injected. I realise there is no hard and fast rule, but someone once told me that more than 4 or 5 can be a code smell. ...
0
votes
1answer
215 views

Is it good practice to create a static class for database tables calculations?

I need to implement some system (using python pandas dataframe in my case) that parses raw data, then adds on calculated data, and then validates that calculated data (boolean output on some columns) ...
0
votes
1answer
83 views

Initiating a class from its static method [closed]

What is the stand on initiating the class from its own static method? Are there any good practices about this? I feel need of initiating a class from its static method while implementing a job ...
0
votes
1answer
355 views

How to output exception messages in GUI applications in order to decouple application code to GUI code?

I want to make GUI applications such that the non-GUI code is independent from the GUI one (let's say I'll use Java 8 and Swing for example). The goal is that I could hypothetically change the GUI ...
-3
votes
1answer
88 views

Should I not use inheritance when I need subtype cast/instantiation from basetype?

Problem BaseType has a field String jsonData that represents a JSON string. The structure of the JSON string differs according to a field String dataType. SubTypeA, SubTypeB, SubTypeC all extends ...
0
votes
5answers
193 views

Clean code for multiple entity representations

I'm wondering what is a clean solution for representing an entity in many different format. Let's suppose I have the following entity: Person { Long id; String title; String firstName; ...
1
vote
3answers
1k views

How can we make a UML diagram (or something similar) for a project which doesn't contains classes (like non object oriented)?

I am working on a python project and I didn't use classes but created different modules and added functions in them. Now I need to draw a diagram to describe the project/application for a paper. I ...
-1
votes
1answer
269 views

What is the programming paradigm when I just use functions in a file to organize my program?

I'm programming a telegram bot with Python and, for a number of reasons, there are no classes in the whole project, just several functions correlated to the the file where they are located. E.g., my ...
1
vote
0answers
62 views

PHP: Binding PDO result values to class properties [closed]

I am new to PHP and am trying to figure out the best practice with respect to binding column values to properties in a class. The column names in the database are not ideal and I would like to extract ...
1
vote
2answers
71 views

Unit conversion of input to/output of public functions/methods

The question/s I'm working on a small scientific Python package. Many of the public methods it is going to offer will have to deal with dimensional input. A wavelength, for example, which could be ...
4
votes
2answers
1k views

Should one make the database calls in the constructor or method of a class?

Take the following instance for example: CreditCardApplication class public class CreditCardApplication { public int Id { get; set; } public string FirstName { get; set; } ...
0
votes
1answer
46 views

How to associate tree nodes with other objects before they have unique identifiers

I've been thinking about a simple software design problem. Imagine I am writing a web application to edit a tree of objects. Each node of this tree has an ID property that is filled in when the node ...
3
votes
4answers
263 views

simple OOP classes right approach

At start, I have these classes in code and consequently tables in the database. Person Company Address Both Person and Company have an address. So I have to establish a relationship between them. ...
0
votes
1answer
80 views

Implementing interface segregation

I am mainly concerned about how to create concrete objects properly when implementing different interfaces. I have a resource whose variants can support different interfaces. For example, say I have ...

1
3 4
5
6 7
60