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

Injecting data processing logic into class

I want find more elegant and appreciate way to inject processors into CommandProcessorDispatcher class. Or it can be another one solution (the goal is separate each command processing logic to ...
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
2answers
51 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 ...
3
votes
3answers
262 views

Difference between composing Factory and inheriting

I'm reading about "Factory method" design pattern from "Head First Design Patterns". So, there is a class public class PizzaStore { SimplePizzaFactory factory; public PizzaStore(...
0
votes
2answers
151 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; // ...
1
vote
2answers
137 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 ...
0
votes
2answers
459 views

How to make method calls more generic when dealing with multiple class types?

I have a loader class that executes data loading functions at boot-time for my application to give me test data. The idea is pretty simple, I'm reading in XML data, using JaxB to turn it into a POJO ...
2
votes
4answers
3k views

What is a software architecture and how to represent it?

I've searched a lot for a clear explanation for a software architecture but each time I got more confused, so What a software architecture really is and is there a standard way to represent it or it's ...
0
votes
0answers
50 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 (...
6
votes
3answers
369 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
1answer
63 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
1answer
157 views

C++11 freeRTOS questions about queue usage and object design

Background I'm writing C++ firmware with freertos to penplottingrobot. It's a makeblock XYplotter and the firmware is connecting to mDraw software for command instructions thru USB drivers. MDraw ...
2
votes
6answers
110 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 ...
1
vote
2answers
84 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
190 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 ...
114
votes
6answers
54k views

What really is the “business logic”?

I'm working with web development since 2009, when I started with PHP. When I moved to ASP.NET I've heard a lot about DDD and OOAD where a lot of focus is given to this "business logic" and "business ...
0
votes
3answers
212 views

Designing a class whose dependancies require “starting”/initializing step

I have Facade class which requires an Endpoint instance to function (it uses it in most of the functions). Endpoint is attached to Platform that is passed in Endpoint's constructor and has to be ...
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 ...
2
votes
2answers
249 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 ...
5
votes
4answers
601 views

Proper way to name a class which has just methods and not fields

GOAL: naming a class which has the responsibility to save data in Android database. The class structure is like this ClassName { public void saveSync(...){ /* implementation*/ } public ...
15
votes
4answers
3k views

Is it overkill to wrap a collection in a simple class only for the sake of better readability?

I have the following map: Map<Double, List<SoundEvent>> soundEventCells = new HashMap<Double, List<SoundEvent>>(); This HashMap maps double values (which are points in time) ...
2
votes
3answers
198 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 ...
0
votes
2answers
112 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 ...
2
votes
1answer
71 views

Designing Models from complex ERP SQL tables

I have a project coming up where im supposed to upgrade an existing access app to a .net architecture. Im wondering how to design object oriented models from the giant tables and mutliple ...
3
votes
3answers
2k views

Is it bad practice to check object types with an identifying member variable?

Preamble: I am making a simple board game in C++, in which AI characters move around squares on the board. There are different types of squares, each inherited from an abstract class, each with ...
0
votes
3answers
288 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 ...
2
votes
4answers
411 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?...
44
votes
11answers
7k views

Are error variables an anti-pattern or good design?

In order to handle several possible errors that shouldn't halt execution, I have an error variable that clients can check and use to throw exceptions. Is this an Anti-Pattern? Is there a better way to ...
0
votes
2answers
87 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 ...
0
votes
1answer
234 views

Can a class factory also save the object to a database?

How can a factory also save the object in the database? I want to create an object that consists of other objects. Pseudocode: firstObject = db.get....; secondObject = db.get....; expectedObject = ...
3
votes
4answers
354 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 ...
6
votes
8answers
710 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 ...
14
votes
6answers
11k views

When are enums NOT a code smell?

Dilemma I've been reading a lot of best practice books about object oriented practices, and almost every book I've read had a part where they say that enums are a code smell. I think they've missed ...
-1
votes
1answer
60 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
76 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
116 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 )...
-5
votes
1answer
2k views

pass a variable as parameter to constructor c# [closed]

pass a variable as parameter to constructor as i want to change the variable value with changeable value i'm new to c# so that i tries to implement one thing in many way i did what i want to do with ...
2
votes
1answer
96 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 ...
17
votes
9answers
3k views

How is polymorphism used in the real world? [closed]

I am trying to understand how Polymorphism is used in a real life project, but I can only find the classical example (or something similar to it) of having an Animal parent class with a methodspeak(), ...
122
votes
14answers
71k views

What is the ideal length of a method for you? [closed]

In object-oriented programming, there is of course no exact rule on the maximum length of a method , but I still found these two quotes somewhat contradicting each other, so I would like to hear what ...
2
votes
0answers
60 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 ...
13
votes
5answers
2k views

What is the meaning of “inversion” in Dependency Inversion design principle? [duplicate]

I'm reading about design patterns. I know what this principle does. High-level and low-level classes depend on abstractions. But why we say this is inversion?
0
votes
1answer
72 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
3answers
394 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
131 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 ...
0
votes
1answer
211 views

Handling Different Parameters for Derived Classes

I'm designing an API and I ended up having a few pure abstract classes. Because of the nature of the problem that I'm solving, each derived class has to be initialized with different sets of ...
1
vote
1answer
85 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. ...
140
votes
8answers
21k views

Are bad programming practices typical within the software industry? [closed]

I just started my first job as a software developer over a month ago. Everything I have learned about OOP, SOLID, DRY, YAGNI, design patterns, SRP, etc. can be thrown out the window. They use C# .NET ...
9
votes
6answers
21k views

What is the better way to escape from too many if/else-if from the following code snippet?

I am trying to write a servlet which does task based on the "action" value passed it to as input. Here is the sample of which public class SampleClass extends HttpServlet { public static void ...
0
votes
1answer
176 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) ...