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
3,379
questions
0
votes
3
answers
3k
views
Is it any more efficient to reuse a variable than to create a new object?
In a project I am working on we load various entities from the database, do some work then attempt to save the resulting entities.
If saving the result is not successful, we return a Result object ...
-1
votes
1
answer
363
views
Modeling a workout schedule using OOP(DDD specifically)
I am just getting into DDD, and I am trying to model a very basic exercise schedule. I have a Schedule and I have a Slot the slot takes 0 - many Exercise entities. The schedule is composed of Slots ...
0
votes
1
answer
112
views
Memento Pattern:Philosophy of createMemento() method in Originator class
I've question about the philosophy of createMemento() in Originator class in Memento Pattern.
My teacher said:
now that Originator class no longer stores Memento objects internally, we should give it ...
0
votes
2
answers
496
views
Payment Processor using polymorphism?
I am writing a payment Processor class, then will take different payment objects in input and talks to external services to process payment.My class is designed using polymorphism as follow:
public ...
1
vote
4
answers
281
views
Software-design for algorithm engineering
I'm currently working on an program that solves a graph optimization problem.
I know the "standard" software-design principles like information hiding, modularization, etc. What I'm ...
0
votes
3
answers
473
views
Tell one, but ask the others?
Consider we have three classes which want to collaborate, then, where is the behaviour?
I guess it can only be in one of the three classes or in a fourth one acting than as a procuedural connector-...
0
votes
2
answers
429
views
Interface and Implementation Classes
I know various forms of this question have come up before, but none of them quite seem to answer in a way that I can apply to / understand in relation to what I regularly see others doing. ...
1
vote
2
answers
589
views
No trivial god-class refactoring
Consider you have the following code:
class UserContainer
{
List<User> user;
//some methods to get specific users, for example users, which are higher than 1,70meters
}
The User have a ...
2
votes
2
answers
3k
views
Should a single method in a service class perform multiple operations for its controller?
Let's say I have a controller called MessageReceiverController which is a controller of an API that other services can call and include messages in the requests.
For each of the messages the ...
1
vote
4
answers
174
views
How to express abstractions?
In a program there is an abstraction from an person to a shape. This abstraction is so that collision detection can be performed. Here is my original class hierarchy:
namespace Graphics
{
class Shape ...
2
votes
2
answers
2k
views
How to go about calling parent's instance method from child instance?
This question is a continuation of a question originally posted here.
I'm trying my hand at creating a Snake clone with JavaFX. One of the
requirements for the game is to have a sort of powerup food, ...
3
votes
2
answers
1k
views
How to design correctly relationships of class diagrams?
I'm learning OOP so I decided to start a new project, a chess tournament manager.
Here you can read about chess tournaments https://en.m.wikipedia.org/wiki/Chess_tournament
Basically the user will be ...
1
vote
1
answer
3k
views
Using isinstance() during exception handling for subsequent action
I've read various posts that polymorphism should be used instead of isinstance, and I agree that makes sense when the use of isinstance is checking the subtypes of a class to determine what to do. ...
2
votes
2
answers
280
views
In OOP, are all class methods valid?
Some classes have methods that don't match up with procedural data abstraction. Here is an example of a problem hierarchy, the Render() method doesn't seem to be part of an procedural data abstraction ...
1
vote
2
answers
139
views
c# template method pattern design question
I'm currently in a situation where I have multiple derived class types(just one is shown in the example below) that need to apply some logic before and/or after calling a method implemented in a ...
0
votes
6
answers
698
views
Designing Entity Objects in OOP
I am newbie to programming and I am confused how to design an entity objects/classes.
For example I wanted to create an animal kingdom in my application.
Do I need to create a single Base Class (...
1
vote
0
answers
354
views
How to use polymorphism in embedded software?
I have been developing a control software in C++. From the high perspective the control task can be basically divided into several subtasks
calculate unmeasurable physical quantity based on dynamic ...
5
votes
2
answers
353
views
GoF Builder Pattern Applicability
The book Design Patterns: Elements of Reusable Object-Oriented Software says to use the builder pattern when
The algorithm for creating a complex object should be independent of the
parts that make ...
-1
votes
3
answers
158
views
Chain of responsibility look alike but choose handler at runtime
Currently I have an structure of PopUps and I've been thinking to use Chain of Responsibility pattern, but the difference is a popup can back to previous one PopUp and also can go to any other PopUp.
...
0
votes
1
answer
410
views
Python: Function pipeline with multiple return/input values, or use OOP? Best Practices?
I have a 'processing' function and a 'serializing' function. Currently the processor returns 4 different types of data structures to be serialized in different ways.
Looking for the best practise on ...
2
votes
2
answers
353
views
Snake Game design
I am designing Classic Snake game using OOPS.I will have the following classes at top level :
Game {
Board board,
Snake snake;
}
Board {
Cell cells[];
}
Cell {
int x,
int y,
...
0
votes
0
answers
18
views
Database Table and Object relationship [duplicate]
I am a Computer Science student and one of my first class was Object Oriented Design (Java). Unfortunately, we never interacted with a database during that class. I am currently working on a CRUD app ...
2
votes
5
answers
1k
views
Object and Tables
I am a Computer Science student and one of my first class was Object Oriented Design (Java). Unfortunately, we never interacted with a database during that class. I am currently working on a CRUD app ...
1
vote
2
answers
133
views
Visitor design pattern usage
I have been implementing a software driver for an external (from my microcontroller point of view) chip communicating with my microcontroller over I2C. From the higher perspective the chip is a ...
29
votes
4
answers
4k
views
Law of Demeter and over-wide interfaces
The Law of Demeter makes sense in some obvious cases.
# better
dog.walk()
# worse
dog.legs().front().left().move()
dog.legs().back().right().move()
# etc.
But in other cases it seems to lead to an ...
0
votes
1
answer
2k
views
Is it better to pass self or the specific attributes in Python methods?
I'm trying to understand when it is better to pass explicit arguments to a method and when it is better to just pass self. I created a little example to illustrate the question.
Here are two different ...
-1
votes
1
answer
2k
views
How can I orchestrate multiple business tasks?
I have a WebApi backend with a Blazor WASM frontend. The application is split up into 3 main parts. Core, Infrastructure and Presentation. Basic onion architecture structure.
Core.Domain Domain ...
-2
votes
2
answers
607
views
Why use private access modifier if we need to access private variables anyway?
Everywhere is said that a private member can only be accessed from inside the same class, but at the same time, we can access the private member using getters and setters, therefore my question is:
...
-2
votes
1
answer
311
views
toppings in pizza factory?
Going through Head First Design Patterns, and their Pizza factory example, it seems that there is no room for specifying toppings.
In general, if I have a process which contacts different APIs which ...
-1
votes
1
answer
209
views
How to avoid cyclic dependency in UI application
I'm developing an UI application where I ran into an issue with a cyclic dependency. Here is the simplified code, to explain the problem.
#include <list>
class UiStyle;
UiStyle* CreateStyle();
...
-1
votes
3
answers
203
views
Object Oriented Programming Benefit
After so many years I started to study again and finally I arrived at the fateful thesis for the three-year degree.
I've been working for 20 years as a systems engineer and I haven't studied ...
3
votes
3
answers
815
views
Use inheritance to make single child, smaller
We have a relatively big class. One of my colleagues thinks we must split this class into a base & child class to make it smaller and cleaner.
On the other hand, I believe when we know this parent ...
6
votes
5
answers
945
views
Avoiding getters and setters: what is wrong with my design?
I have a class that wraps a map UI element: Map.
The map can have overlays that appear on top of it, in both side panels and modal windows. When these UI elements appear, I want to temporarily disable ...
0
votes
0
answers
300
views
How can I use the Factory pattern and expose my factories to consuming code without introducing transitive dependencies on the constructed types?
I have a C# class called FileTransferManager. Previously it took some parameters such as a username and password to connect to a FTP server. However now I have an additional requirement to support ...
1
vote
1
answer
126
views
OOP Design - Null Object Pattern or design pattern
Consider the code snippet
public interface Car
{
string getColor();
void Drive();
}
public class CarWithAutomaticTransition : Car
{
public string getColor() { return "Red"; }
...
0
votes
0
answers
90
views
c# class structuring and appropriate coding techniques
I have 2 classes that share some properties
public class SportsUser
{
public string errorCode { get; set; }
//the sportsuser and SportsAdminUser is from a different database hence the long and ...
3
votes
0
answers
100
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 ...
3
votes
2
answers
1k
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 ...
9
votes
4
answers
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
4
answers
871
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 ...
5
votes
4
answers
369
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 ...
2
votes
2
answers
337
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 /...
12
votes
4
answers
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<...
1
vote
1
answer
267
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 ...
79
votes
10
answers
17k
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 ...
2
votes
0
answers
115
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 ...
0
votes
2
answers
514
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<...
1
vote
1
answer
120
views
Refactoring similar 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 ...
-2
votes
2
answers
206
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 ...
-5
votes
2
answers
1k
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 ...