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
0
votes
1answer
32 views

Software driver for remote digital inputs

I have been facing a task to develop a software driver in C++ for a chip which makes available 8 digital inputs over the SPI bus. In the time being I have been thinking about the interface of the ...
0
votes
5answers
109 views

Is this a proper use of overriding according to LSP?

I have a abstract class named MotorizedVehicle that contains an implemented gas- and brake-function. I want to make a Truck class that extends this class and uses gas exactly in the same way as ...
6
votes
2answers
265 views

Suggested OO Design Pattern for a Query Builder

Essentially, I'm building a Query Builder (in C#, if that's relevant) which has this sort of interface, exposing more statically typed functions as the query gets more refined. AnimalQueryBuilder - ...
0
votes
1answer
94 views

Design leading to break contravariance. How to avoid it?

I have a Converter which use a Resolver to determine which Factory to use when converting a Resource to a Entity. To do so, I need to be sure that the Factory has a createFromResource method. The ...
3
votes
2answers
353 views

Does OOP overemphasize the importance of noun and thus put action/verb in the less importance position ? [closed]

Steve yegge wrote an article called "Execution in the Kingdom of Nouns" back in 2006, 14 years later I still find the points he made valid. For example, "Action is what gives life its ...
-3
votes
0answers
62 views

Global data structure in java program

I have an engineer question. How I can better realize global data structures like Property class or database connection pool. I can do it with a static class with a static instance on that class or ...
-4
votes
1answer
53 views

What's the best way to design a state machine with different object inheritance

I have a class A and class B, both derive from the same parent class. Each object has a state machine inside it that defines it's behaviour. The behaviour is different though depending on if the ...
-7
votes
1answer
98 views

method and class overloading (good programming practice or ridiculousness) [closed]

I have yet to hear an answer from anyone as to why overloading of any type is a sound programing practice. Calling the same function name with an almost infinite number of variations on the surface ...
3
votes
4answers
517 views

What information should a Game Piece hold?

In an OOP design, suppose I have some board type game that has pieces, such as chess, checkers. In you opinion, what properties should pieces of that game board have? imo, I feel like the pieces ...
-1
votes
1answer
102 views

Loose coupling with inner classes

I just have a quick question as I couldn't find any concrete answers on the web. Does having a private static inner class promote loose or tight coupling between it and the outer class in Java? Thanks ...
2
votes
2answers
70 views

Action objects VS handle/service-methods

a short question: class ItemActionObject { private final Object moreParameters; private final Object otherDependencies; private final Item item; public ItemActionObject(Item item, ...
1
vote
2answers
114 views

Is there a difference between abstract data type and interface?

From what I understand, an abstract data type is basically some data and what we are allowed to do with that data (ex. a list with a set of data and an attribute size and the functions get(), set(), ...
-1
votes
1answer
51 views

Split object into multiple objects while keeping reasonable performance

I'm using C# but the problem could also be with Java. I have an object in the flow that is muted for setting up some properties during the flow of the program. Let say public class Person { public ...
2
votes
4answers
196 views

Is it correct to say “send a message to an object” in Java?

In Smalltalk we say "send a message to an object", but is it also correct to say "send a message to an object" in Java, or is it only correct in Java to say "call a method of ...
5
votes
6answers
362 views

Structuring a long sequence of operations

Imagine a production line - say, building a car. Starting from the beginning, a long, defined sequence of operations takes place, and at the end a car comes out. At various points along the way, ...
17
votes
9answers
4k views

Which object should have the method?

I am trying to create an object model for a user and a chatroom. I'm stuck on where to place certain functionality when the objects collaborate. At the moment all the functionality for the User is ...
3
votes
1answer
139 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 ...
2
votes
4answers
186 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
36 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
2k 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
1k 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 ...
70
votes
11answers
12k 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
337 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
126 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
156 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) { ...
-1
votes
3answers
153 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
68 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 &...
5
votes
3answers
500 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 ...
82
votes
12answers
24k 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
92 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
125 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-...
5
votes
2answers
258 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 ...
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
90 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
43 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
193 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
120 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
422 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
346 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
102 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
262 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
121 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
148 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
112 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
140 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
396 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
30 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
186 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. ...

1
2 3 4 5
61