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
2
votes
1answer
40 views

Does overriding this method violate LSP?

If a base class Logger has a method reportError that takes an Error object and formats it as a string. If a subclass implements that method but outputs the string in a different format, yet a string ...
1
vote
4answers
133 views

When are Description classes useful

A book called 'Applying uml and patterns by craig larm' emphasized the use of Description classes in software designing. For example, the book pointed out why putting attributes such as description, ...
0
votes
1answer
29 views

When dealing with session level data in a web app, is it better to maintain a static store of that data, or pass it around as needed?

I have a web app that is capable of connecting to multiple databases that are identical in structure but contain different data; each of our clients who uses the app gets their own copy of the ...
7
votes
6answers
1k views

Is programming an emulation of the real world? [closed]

Assume that we have a car in the real world, this car would be composed of atoms, and we can do operations on this car (for example: we can move the car or change its color, etc.). And assume that we ...
5
votes
6answers
851 views

Are Car objects and Dog objects used in real life programs?

While learning about OOP, I have noticed that a lot of the tutorials give examples of objects such as Car objects and Dog objects, but I don't know if these kind of objects are used in real life ...
-4
votes
0answers
31 views

Best Practice for lifting classes from 2d to 2d in python

I am currently writing a simulation in python which is running in 2D. I want to extend it now to 3D and therefore I have to change the classes like the simulation grid. My question is what is ...
39
votes
10answers
6k views

What benefit do we get by thinking of objects as “sending messages to each other”?

I have read that in OOP, we think of objects as "sending messages to each other", for example if we did car1.stop(), we say that "we sent the message stop() to the car1 object". ...
5
votes
9answers
317 views

Is allowing making member variables private considered a feature of OOP?

I have read in some tutorials that one of the differences between procedural programming and OOP is that OOP allows you to make member variables private, while in procedural programming you can't make ...
3
votes
2answers
121 views

Composing and Inheriting from the Same Type

To start off with an example: I have a read-only Repository used for getting arbitrary values. This behavior can be implemented multiple ways. I also want to allow opt-in mutation of the repository's ...
-3
votes
2answers
51 views

What pattern for different data descriptions

We need to call a webservice which registers a shipment with either UPS or TNT. You fill in some details, call the function to register and pass json for details. Pretty basic stuff. Shipment shipment ...
1
vote
2answers
147 views

How to avoid cascading dynamic casts?

So, in general casting and dynamic_cast in particular are to be avoided. But I don't see a proper alternative for this: List<DerivedA*> ListA; List<DerivedB*> ListB; Bool Add(Base* obj) { ...
0
votes
3answers
131 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
2answers
67 views

Relation many-to-one between objects in Python

I'm doing scientific computations using Python. So far I have a module core and a class Simulation inside. There are many instances of Simulation at the runtime but all of them must share the same &...
4
votes
3answers
464 views

How could a computer program do anything if everything is immutable?

I feel this is a bad question because I probably do not understand what I am talking about. In my effort to learn about functional programming, I became stumped on understanding the idea of immutable ...
81
votes
12answers
23k views

What is the utility and advantage of getters & setters especially when they are merely used to read and assign values to properties of an object? [closed]

I’m still really new to learning to program. Just learning the syntax for a few programming languages at the moment. The courses I viewed for C# and Java touched only very briefly on getters & ...
-3
votes
3answers
87 views

is python(cpython) code represented as c code by the interpreter?

what i know is , in cpython when we run a code then its first compiled into byte code and the cpython interpreter( which is written in c interprets it) interprets the byte code and converts it into ...
0
votes
4answers
120 views

How does Object Oriented System or Decomposition supports reuse?

The 1 logic is that due to inheritance. But, except that how does Object Oriented Systems helps in reusability? I have read this article below. https://www.drdobbs.com/a-realistic-look-at-object-...
-4
votes
0answers
51 views

What is the best way to design a program that has a large amount of derived classes?

Given the base class "Command" and (hypothetically) 100's of derived classes e.g "OpenCommand", "CloseCommand", "JumpCommand".etc. What is the best way to ...
5
votes
2answers
251 views

Can the Liskov substitution principle be encountered when building real-world frontend applications?

I know about the LSP, which requires that objects of a superclass shall be replaceable with objects of its subclasses without breaking the application. However I've been building frontend applications ...
-1
votes
0answers
58 views

Best practice to connect multiple components of a game

I'm in the process of linking a game (made in pygame) together. The directory has several files that contain classes for different components of the game, which all have corresponding demos (if not ...
11
votes
2answers
2k views

Does TDD contradict the open-closed principle?

My understanding of the TDD methodology is that (failing) test cases are written promptly after finalizing the requirements. My understanding of the open-closed principle (in the context of OOP) is to ...
-1
votes
1answer
87 views

Refactoring: Pythonic way of reducing the subclasses?

background: so, I am working on an NLP problem. where I need to extract different types of features based on different types of context from text documents. and I currently have a setup where there is ...
-1
votes
1answer
42 views

Does adding a method to a sub-class with the same name of the parent class method, break substitutability principle?

Let T be a superclass, and S derives from it: abstract class T{ public virtual byte[] Foo(string str){...} } class S : T{ public override byte[] Foo(string str){....} public byte[] Foo(string str, ...
5
votes
1answer
188 views

Create C++14 library where each class has 2 similar variants

I'm writing a C++ library which does some computation on vectors of audio data. The library supports both GPU (using Thrust, a C++ STL-like library for GPUs) and CPUs (using the STL). I'm using CUDA ...
1
vote
2answers
117 views

Choosing between DI (without container) and Composition

I'm working on a classes that are designed to read a defined file format; said format is comprised of 2 separate files (FileA and FileB). For ease of use, the format is referred to as the FileA format,...
1
vote
4answers
419 views

The point of sealing a class

What is the point of sealing a class? Why should we seal a class at all? I've found a bit contradicting answers on the internet, for example here: https://stackoverflow.com/questions/268251/why-seal-a-...
2
votes
3answers
340 views

How to not violate the single responsibility principle?

Let's say I'm writing a class that tracks a single stock ticker. In this simplified example, the StockTracker class holds a string that tells me the trend direction and a variable window that holds x ...
0
votes
2answers
100 views

How can you avoid doing hundreds/thousands of queries when utilizing classes in PHP?

I have been dipping my toes into object orientated PHP programming and I'm finding it useful but I can't help but feel I'm missing something in regards to how to utilize it. Normally my classes and ...
-1
votes
3answers
239 views

Is throwing custom exceptions from private methods OK?

(I moved this question here, as StackExchange fits better, originally I posted it on StackOverflow.) This is not a question about a particular piece of code, rather I ask what is the right design ...
1
vote
3answers
116 views

Design with subclasses being aggregates of classes implementing interfaces

I have modelled a class structure, where subclasses Rectangle and Circle inherit from an abstract superclass Figure. All subclasses share an interface IGeometry that provides for getArea() and ...
2
votes
2answers
147 views

How does a function's purpose differ between a OOP and Procedural style?

A while ago, I saw a Stack Overflow answer (I can't seem to find it now) that says functions and methods have different goals. A method is to change something within the instance, while a function is ...
0
votes
1answer
111 views

Have the same logic in two different class hierarchies

I have the following class hierarchies abstract class Base<T> { abstract T getRelevantType(); } class A : Base<AType> { AType getRelevantType() } class B : Base<...
3
votes
1answer
137 views

How choose between functions or objects

I've seen different approaches and it's not clear to me which one is the correct one. Some dev use lots of small, very specific objects and use to compone them is some way to achieve their goal. ...
5
votes
6answers
390 views

How to modify object properties?

I've recently read a great article about unit testing. There was an example of a bad method which is not well designed. It looks like this public static string GetTimeOfDay() { DateTime time = ...
0
votes
0answers
28 views

Multiple external API calls and only one valid response depends on the parameters value

In my microservice I need to call several external API. The problem is that I do not know which of them to call to get a proper response, but I am sure that one of them return a successful response. I ...
8
votes
4answers
3k views

OOP Design considering no modifications to existing design

The question is: interface Animal { void eat(); } class Lion implements Animal{ public void eat(){ //do somethng } } class Test { public static void main(String[] args) { ...
-1
votes
2answers
183 views

Unit testing private methods

preface: I know this topic has been asked about a lot on here in the past. Hopefully I will make it clear that I've read a fair amount of the questions/answers on the topic, and other literature, too. ...
0
votes
2answers
116 views

Should it be considered a BC break to return clone instead of new self?

(This question applies to the equivalent code in both Java and PHP) I have a class like this: class Foo { private int $bar; public function __construct(int $bar) { $this->bar = $...
1
vote
3answers
156 views

Is it a good practice for functors to store outputs as instance attributes?

The question pretty much says all, but let's look into a simple example (I'm using C++, but the question is not strictly related to any particular language): So, let's say that we have a functor that ...
2
votes
4answers
242 views

Altering the state of a composed class by its composing classes. Is there any rule or principle for not doing so?

In other words, is it good to define the method that removes an element in a collection inside the class representing the element, considering a composition relationship? Something like: listElement....
2
votes
2answers
74 views

Updating properties with vertical slice architecture

In Vertical Slice Architecture (VSA) you are supposed to have a class for pretty much every operation you can do (as I understand it). Some example, also mentioned in the referenced article, are: Get ...
15
votes
9answers
6k views

What does “representing” something in memory mean in OOP?

While learning about OOP, I have found that the term "represent" is used a lot in OOP tutorials. For example I may find a statement like this: "a car object represents a real life car&...
0
votes
2answers
69 views

Which approach is better suited for analyzing a basic manual ongoing system? Structured Analysis or Object Oriented Analysis?

My task is to analyze a system used in our office which is based on Excel for storing data. The data is entered manually by a person. So when we need to update or edit the data, we use Excel's ...
2
votes
2answers
114 views

Should base class include unused properties of sub class?

I was looking at the angular documentation and noticed this code: export class QuestionBase<T> { value: T; key: string; label: string; required: boolean; order: number; controlType: ...
-2
votes
2answers
86 views

Select from many-to-many in one query

A common issue I run into when building CRUD applications is how to retrieve many-to-many relationships from the database and put them into an object model. Say, for example, I have the following data ...
1
vote
1answer
85 views

Pipeline design pattern and immutability

I'm developing a backend service that is supposed to process items in a pipeline-fashion. Each stage is essentially a Function<IN, OUT>. So the current stage's input is the previous stage's ...
-2
votes
2answers
57 views

How to design a flexible multi-criteria prioritization?

Let's assume that we have a set of valid results, ex. Fruits: "Apple, Banana, Kiwi, Pear, ...". (In reality, it’s not fruits but complex objects) Now we need to pick the best result ...
0
votes
3answers
132 views

How to choose between these different options for communicating between objects?

I have a few objects that should communicate between each other. I also want to have my code unit tested. I am questioning how I should handle their communication: Should I make one instantiate the ...
2
votes
1answer
84 views

Converter implementation in Python: class versus module?

I've written a little library that uses the builtin ast library to convert between functions, docstrings, argparse .add_argument, classes, and [soon] more. Stubs look something like this, with ir ...
1
vote
1answer
164 views

How can I do memory management in C++ when a class needs to throw out and replace a member object many times during its lifetime?

I'm writing a C++ application. This is a memory management question, I have a background in scripting languages and am new to C++. I have a little class representing a GUI view, call it View, and ...

1
2 3 4 5
61