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
votes
3answers
69 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
100 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
47 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
189 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 ...
-2
votes
0answers
58 views

When writing a fluent interface, shoule one return the calling object of a function, and returning a memberwise copy of the calling object? [closed]

I have an scenario where a fluent interface really does make the most sense. That said I've never actually had to write one before, or paid the most attention when using one. I realized that a fluent ...
-2
votes
0answers
54 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 ...
9
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
86 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
40 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, ...
4
votes
1answer
176 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
116 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
399 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
334 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
95 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
223 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
108 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
385 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
179 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
114 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
155 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
241 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
69 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
68 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
111 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
81 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
161 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 ...
7
votes
3answers
380 views

SOLID, Does Liskov Substitution Principle (LSP) conflict with the Interface Segregation Principle (ISP)?

I am confused by the two principles of SOLID, liskovs substitution principle and interface segregation principle. It seem as though they conflict each other's definitions. How can a class that ...
0
votes
1answer
61 views

Could a getState() method in a Caretaker violates Memento Pattern?

After looking at several examples of implementation of Momento on the internet, I wondered whether it is correct or not to retrieve the status of Originator, being much more accurate, whether it is ...
0
votes
2answers
157 views

How to visualise Inheritance and Polymorphism?

I want to make diagrams that explain how Inheritance and Polymorphism work conceptually. Assume that we have a Cat class that inherits from the Animal class. The way that I can think of a Cat object ...
2
votes
2answers
92 views

Builder Pattern: Is there any advantage of having instance variables + product reference instead of just product reference?

Consider the product class: class Car { private String color; private String model_num; //getters and setters for the above fields } Consider builder class 1: class CarBuilder1 { private ...
0
votes
2answers
137 views

Retrieve all objects of the same specific class from an abstract class

I have an abstract class called ProjectItem and I have 2 specific classes. One of them is called Task and the other is called Deliverable. I have to put all the ProjectItems inside a list, which I did,...
0
votes
0answers
76 views

Using for_each instead of iterators to avoid iterator invalidation

I am writing a simple custom (special purpose) container and would like to allow for iteration over each element, however, avoid using iterators due to the problem of iterator invalidation. Instead of ...
2
votes
3answers
566 views

Can writing Object-Orientated Code in a Functional style improve performance?

Given a scenario where you have consecutive setters or a series of events where an object is modified, can it be more performant to instead write code in a way where a new state is returned rather ...
0
votes
4answers
192 views

C# refactoring with inheritance

I have two classes which contains almost same method. How can I refactor this with inheriting one class by other class. class A{ public void run(){ // task 1 // task 2 // task 3 } ...
1
vote
4answers
115 views

Removing a base class from its according collection OOP

Lets say i have a zoo class, with a bunch of collections. The collections are giraffes, elephants, tigers etc. All animal types derive from the same interface or base class, lets call it IAnimal. So ...
-2
votes
1answer
83 views

Simple circular dependency between three classes

I have this basic design with a circular dependency. Is there any solution for this? The problem is that a Machine cannot be created if a Model for that Team has been submitted.
1
vote
2answers
178 views

Is there a statically typed programming language that implements Polymorphism without using a superclass or an interface?

Is there a statically typed programming language that implements Polymorphism without using a superclass or an interface (if such implementation is even possible)?
0
votes
2answers
248 views

Terminology: Classes that contain only methods [closed]

I am studying the programming language Kotlin, and I just came across the idea of a Data Class. I have a background in Java programming where classes can have fields and methods. I have heard ...
1
vote
3answers
138 views

Can two unique messages share the same name in OOP?

In this question, the asker of the question shows the following example (no Polymorphism is used): circle1.draw(); rectangle1.draw(); And the highest voted answer says the following: In your example,...
2
votes
1answer
88 views

What is the design of libraries like cairo and OpenGL called?

I'm not a software engineer, so sorry if the question is elementary. Usually, functions provided by libraries written in C receive a handle from the calling program. This handle directly (if it's a ...

1
2 3 4 5
61