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
10
votes
8answers
3k 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&...
1
vote
2answers
42 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 ...
0
votes
1answer
90 views

Could this be considered a valid State GoF Pattern implementation?

For teaching purpose, I would like to create a simple implementation of State Pattern using PHP 7.4. So, I've tried to create a simple "document state machine" starting with Draft, sending to review ...
0
votes
2answers
64 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
1answer
79 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 ...
76
votes
8answers
92k views

Why have private static methods?

I just wanted to clear up a question I have. What is the point of having a private static method as opposed to a normal method with private visibility? I would have thought an advantage to having a ...
0
votes
1answer
78 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
258 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 ...
1
vote
2answers
102 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
81 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 ...
-2
votes
2answers
55 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 ...
1
vote
1answer
73 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 ...
0
votes
3answers
127 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 ...
24
votes
6answers
6k views

Visitor Pattern: what's the point of the `accept` method?

I'm trying to fully understand the visitor pattern. What I've learnt so far (correct me if I'm wrong) is: It's about adding operations to classes, without modifying the source code of those classes. ...
2
votes
1answer
134 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 ...
0
votes
1answer
40 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 ...
1
vote
1answer
147 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
327 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 ...
20
votes
7answers
17k 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 ...
0
votes
2answers
156 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
90 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 ...
2
votes
3answers
554 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
181 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 } ...
0
votes
2answers
129 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,...
2
votes
1answer
85 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 ...
0
votes
0answers
72 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
1answer
73 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
171 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
235 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
4answers
114 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 ...
13
votes
6answers
1k views

Clean OOP way of mapping an object to its presenter

I am creating a board game (such as chess) in Java, where each piece is its own type (like Pawn, Rook etc.). For the GUI part of the application I need an image for each of these pieces. Since doing ...
11
votes
2answers
2k views

Can we really use immutability in OOP without losing all key OOP features?

I see the benefits of making objects in my program immutable. When I am really deeply thinking about a good design for my application I often naturally arrive at many of my objects being immutable. It ...
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,...
3
votes
3answers
202 views

Decoupling and Command Pattern

I am working on some project to learn how to make bigger and better software (multiplayer game) and I found a problem about having in my code a design pattern Command Pattern and anti-pattern God ...
46
votes
9answers
12k views

Return considered harmful? Can code be functional without it?

OK, so the title is a little clickbaity but seriously I've been on a tell, don't ask kick for a while. I like how it encourages methods to be used as messages in true object-oriented fashion. But this ...
4
votes
2answers
415 views

What's wrong with using a Singleton?

I'm working on a Python application in which there are two Singleton classes: App and Configuration. The former seems straight forward, only ever instantiate one App instance; the latter seems ...
25
votes
7answers
6k views

Can abstractions and good code practice in embedded C++ eliminate the need for the debugger?

I am a C developer for an embedded system. YouTube has recently started recommending "C++ for embedded systems" talks. Having watched some of them, they pique my interest, but none of them answer the ...
7
votes
4answers
595 views

Why does C++ have classes?

The title is deceptive; the question is really "why does C++ have classes and not only structs?" Often, people ask why C++ has structs if they are functionally equivalent to classes. The answer is (...
0
votes
1answer
82 views

Are inheritance, abstraction and polymorphism regarded as association in OOP?

In the realm of OOP, inheritance, abstraction and polymorphism are basic concepts of the paradigm. On top of that, there also have the concept called "associations" which I understand is ...
0
votes
2answers
81 views

Can other behavioral OOP design patterns be expressed in terms of Strategy and Template Method Patterns for behaviour parameterization?

I'm studying OOP design patterns in a solution-oriented way which I mean not concentrating just one pattern but with a comparative analysis like their combined or hybrid usages and equivalents in ...
1
vote
6answers
24k views

changing value of a private member of a class in c++ without using member or friend function

Using pointer, I am able to modify the private value of the class in the code below. Does it violate the C++ concept that private member can only be modified by member or friend functions? #include&...
-5
votes
1answer
109 views

Use Case Diagram for Vending machine

I want to create a use case diagram for a vending machine which has the following states: Accepts coins of 1,5,10,25 Cents Allow user to select products Coke(25), Pepsi(35), Soda(45) Allow user to ...
1
vote
4answers
182 views

Is thinking of an OOP object as a “small program” a good analogy?

I have read that we can think of an OOP object as a "small program" that send messages to other "small programs" (objects), but I am not sure if this is a good analogy. One reason ...
1
vote
1answer
43 views

Inheriting DBModels and UI Models from Domain Models

I made a pretty simple CRUD API to store customers and some related information in a database. My customer has 20 properties like Name, Telephone etc. that are all stored in an anemic domain model. My ...
1
vote
5answers
342 views

Why OOP languages use the syntax “object.function()” to send a message?

In C++ and Java and many other OOP languages, in order to send a message to an object, you have to use the object.function() syntax, for example: myCar.start(); // send the start() message to the ...
4
votes
3answers
240 views

Working with “external” object identifiers

Note: I wrote this question in a way that made it seem I'm mainly concerned with the memory usage and ways to optimise this. Rather, my original intention (and my current intention, upon revisiting ...
-1
votes
2answers
168 views

Structuring PHP classes that need to return multiple objects

I am trying to plan out php class structure for an order processing project. I've used classes before but I'm still not an expert on OOP yet. I've been searching for hours and can't seem to find the ...
1
vote
4answers
267 views

Is checking the type of a variable antithetical to OOP?

As an example, in PHP you can run gettype($myVariable); to obtain the type of a variable $myVariable. Is such functionality antithetical to OOP principles?
11
votes
5answers
2k views

Looking for an effective pattern to cope with switch statements in C#

I sometimes end up with services encapsulating the responsibility of doing some sort of business process for which there are several possible outputs. Typically one of those output is success and the ...
1
vote
1answer
83 views

Design Patterns: Factory Pattern Vs. getInstance Inside Abstract Class

I'm working on an app where we need to use different authentication flows depending on how the user is accessing the app. I want to make sure that there is only one instance of the authentication ...

1
2 3 4 5
60