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
37
votes
5answers
3k views

How is defining that a method can be overridden a stronger commitment than defining that a method can be called?

From : http://www.artima.com/lejava/articles/designprinciples4.html Erich Gamma: I still think it's true even after ten years. Inheritance is a cool way to change behavior. But we know that it's ...
1
vote
2answers
130 views

Collect Data of different Modules inside a Monolith

During my first attempt of implementing a project with the "Clean Architecture" I try to implementation a job portal where I came across a problem concerning the communication between (...
2
votes
0answers
64 views

Refactoring nested if-else statement [duplicate]

I have an app where every object is checked based on various types of business rules. For this, i used multiple nested if-else statement which was done in one class. I am not happy with this situation ...
16
votes
2answers
14k views

Why are inheritance, encapsulation and polymorphism not the pillars of OOP? [closed]

One day I went to a Stack Overflow chat and saw a phrase, that was stating that inheritance, encapsulation, and polymorphism are the pillars of OOP (in the sense that they are fundamental, a ...
0
votes
1answer
91 views

DDD design: Tracking price calculation progress and fallback price calculation

I am pretty new to DDD, so any help/ideas will be appreciated. I will explain my initial design and problem below. The user can ask the system to generate products proposal, proposal is basically ...
2
votes
2answers
108 views

Is there a canonical list of standard verbs to use for method names?

I was trying to explain something to a junior programmer the other day, and as part of it I had to explain that: a method with 'find' as the verb in it, will either find an item and return it, or ...
3
votes
3answers
129 views

How to deal with different level of abstractions (blurred line between data and models)

My question is about the way to represent data models created at runtime. To illustrate, let's say we would like to create a CMS-like app in which end-users may create custom forms. Those forms are ...
8
votes
4answers
2k views

Represent individual object as a class?

What is the best way to model the objects in my OOP program? I understand that the classes represent not particular objects but "groups"/"generalizations" of objects. But, I need ...
2
votes
4answers
250 views

Is using getter method violating the law of Demeter?

Suppose I have a Attendance class public class Attendance { private PersonInfo personInfo; public PersonInfo getPersonInfo() { return personInfo; } } And I want to check if person is ...
11
votes
4answers
2k views

The role of OOP in the business layer

Below, I define an IInstantNotification Interface. TextNotification Class and EmailNotification Class inherit from this interface. public interface IInstantNotification<T> { List<...
11
votes
7answers
2k views

Is separating most classes into data field only class and method only classes (if possible) a good or an anti-pattern?

For example, a class usually have class members and methods, eg: public class Cat{ private String name; private int weight; private Image image; public void printInfo(){ ...
2
votes
2answers
82 views

What does abstraction mean in Bridge design pattern?

The bridge pattern is defined as 'The Bridge pattern decouples an abstraction from its implementation, so that the two can vary independently'. I get that abstraction here doesn't mean abstract class /...
36
votes
4answers
10k views

The principle of least knowledge

I understand the motive behind the principle of least knowledge, but I find some disadvantages if I try to apply it in my design. One of the examples of this principle (actually how not to use it), ...
44
votes
10answers
10k views

How functional programming achieves “No runtime exceptions”

How does a functional programming language, such as Elm, achieve "No runtime exceptions"? Coming from an OOP background, runtime exceptions have been part of whatever framework that is based ...
1
vote
3answers
17k views

Simple real-world PHP OOP example?

I'm trying to learn PHP OOP, but when I've followed tutorials, all the examples seem to involve things like: class Human { $_sex; public function setSex($sex) { $this->_sex = $sex;...
2
votes
5answers
9k views

When to use Interface variable = new class variable OOP

I saw often people use this code like interface IAnimal { void die(); } class Cat : IAnimal { void die() { ... } void meow() { ... } } IAnimal anAnimal = new Cat(); Cat aCat= new Cat()...
1
vote
1answer
137 views

Is this correct adherence to Liskov Substitution Principle?

I used to have a base object with subtypes behaving in all but the same way -- the difference being in their render methods. This base class defined a default render method, overridden by Some ...
1
vote
2answers
1k views

UML - Identifying use cases and actors

I'm currently learning object-oriented programming and we have moved on to UML. We are learning about use cases and actors currently and we need to create a list of actors and use cases initiated by ...
6
votes
2answers
10k views

What are the pros and cons of multiple inheritance? [closed]

What are the consequences of allowing multiple inheritance in a programming language? What characteristics of multiple inheritance create an environment such that the use of multiple inheritance ...
2
votes
4answers
13k views

What exactly are SDLC and OOP?

I have been asked "What are SDLC and OOP?" many times in job interviews but I am still not sure how to answer this question. I am a web developer for quite some time but I still have problem with ...
2
votes
0answers
72 views

How to design software driver for the analog to digital converter?

I have been developing software driver for the analog to digital converter in C++. The a/d converter is primary intended for conversion of the temperature signals. The temperature signals are then ...
-1
votes
2answers
77 views

Ideas for implementing a hardware interface

I am looking for alternative ideas of how to implement the following situation (.NET Core, C#) Having multiple sensors that communicate over a RS485 interface with the host. Each sensor is implemented ...
0
votes
2answers
109 views

Object Oriented Design for chess

Recently I came across some article on Chess OOPS design.Following is some snippet from it: public class Chess { ChessBoard chessBoard; Player[] player; Player currentPlayer; List<...
0
votes
0answers
22 views

Design pattern for duplicating lines of code in control structures [duplicate]

on my website I have a multi-page form where user can pass some data on each view, but user can also save a draft on specific step(in my example 1-4). My service has a dispatch method. Based on step(1-...
8
votes
4answers
1k views

Definition of “Behaviour”?

What is exactly meant when software-engineers talk about "behaviour" in contrast to "state" (Definition of "state")?
0
votes
2answers
132 views

Is using an enum to differentiate different events in an observer pattern plausible if it's on a small scale?

I need to collect statistics during an algorithm. To not mix the statistical code with the algorithm code too much, I'd like to decouple that by publishing "statistical events" that can then be ...
1
vote
1answer
39 views

Refactoring simillar integration service code block

Context: Creating a "middleware" between 2 services I have to Get data from Service Source and get it into Service ERP. There is a multiple type of Data: A, B, C. An integration process ...
4
votes
2answers
258 views

Most expressive way of allocating member data, per Stroustrup

I was watching a lecture by Bjarne Stroustrup from 2014, on "The Essence of C++". About halfway through he rather forcefully recommends not using new, delete, or pointers for class member ...
7
votes
2answers
2k views

Is there such a thing as a workflow pattern? or how to do a workflow properly?

(and alternatives to a workflow engine) Problem: I have various inputs with various attributes. For example {name: john, country: US} and {name: Jose, country: MX} And I have the following workflows ...
26
votes
3answers
22k views

Generics vs common interface?

I don't remember when I wrote generic class last time. Every time I think I need it after some thinking I make a conclusion I don't. The second answer to this question made me to ask for ...
-5
votes
2answers
77 views

How can you call a function from within a constructor when the contractor is defined before he function definition?

I have gone through multiple posts but am unable to find an answer to my very basic question on classes and so asking it here, it would be great if someone could shed some light on this topic- I have ...
3
votes
1answer
733 views

Separate business logic from ORM models in SQLAlchemy

I have a Flask application with tens of complex models, almost all of them related to each other. A simple pseudo-schema of some of them: +----------------+ | FoodGroup | +-------+--------+ ...
-2
votes
0answers
40 views

How to check environment in NodeJS in an object-oriented way?

I'm refactoring my NodeJS codebase right now and I've recently moved to using TypeScript. I'd like to use Object Oriented Design principles in my project. Ideally, I'd also like to make sure my ...
0
votes
1answer
77 views

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

I have looked at several examples for implementations of Momento on the web. I wonder if it is correct to retrieve the status of Originator, since this is much more accurate, up-to-date and reliable? ...
1
vote
2answers
150 views

What's the difference between a pure function that expects a complex object of a particular type and object oriented programming?

What's the difference between writing OO code that depends on internal state and writing a pure function that expects an argument that is a data structure of a specific type (and thus has internal ...
0
votes
1answer
706 views

The finer points of HMVC

I'm new to HMVC and whilst tutorials are great about dealing with the overall details of keeping modules separate and only letting controllers communicate, they aren't so great at explaining the ...
5
votes
7answers
636 views

A problem of decoupling

This is a simplified version of a problem I'm facing in my current project. Let's say we want to display shapes: rectangles, circles, etc. I'll have a Shape class which is subclassed by Rectangle, ...
1
vote
2answers
107 views

How does one choose where to place logic which converts data between two formats/representations?

Suppose I have two "modules", A, and B (I'm choosing not to use classes, because you generally can't create an instance of a module, which makes this question simpler). These modules contain ...
-4
votes
1answer
41 views

Efficient database for multiple key searching?

I'm trying to implement a solution that stores every product from a shop, and then allows me to search them either by ID (an integer index), description (string) or barcode (string). The idea I came ...
0
votes
1answer
69 views

Does every use of events count as implementing the Observer Pattern?

Lets say I have the following code in my GamePanel class: public GamePanel(Menu menu){ this.addMouseListener(new PlanterListener(this)) PlanterListener class: public PlanterListener(GamePanel game){ ...
7
votes
2answers
9k views

Using the Decorator pattern to add public methods to an object

The Decorator pattern is usually used to extend the functionality of an object by extending one of it's current methods. To illustrate, please consider an object object and a decorator decorator. ...
-1
votes
2answers
103 views

What design/component principle did I apply? How can I further improve it?

I recently refactored a program for code feasibility and maintainability; however, I am totally unaware of what software principle I did implement. I just followed my feeling. The purpose for this ...
0
votes
1answer
104 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
1answer
89 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
38 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
124 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 ...
3
votes
2answers
440 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 ...
5
votes
4answers
5k views

How to reach the parent object?

I have a parent object that has some other objects as fields. The parent object fully owns these fields: they can be declared as fields of the parent object (MyPart part), directly, not as references. ...
2
votes
1answer
152 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 ...
13
votes
6answers
9k views

DDD Injecting Services on Entity Methods Calls

Short format of question Is it within best practices of DDD and OOP to inject services on entity method calls? Long format example Let's say we have the classic Order-LineItems case in DDD, where ...

1
2 3 4 5
62