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
0answers
11 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 ...
1
vote
4answers
71 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 ...
2
votes
2answers
84 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
2answers
78 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 /...
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<...
1
vote
1answer
134 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 ...
43
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 ...
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 ...
0
votes
2answers
107 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-...
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 ...
-1
votes
2answers
76 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
2answers
76 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 ...
-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 ...
4
votes
2answers
253 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 ...
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 ...
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){ ...
-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
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 ...
6
votes
2answers
293 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
98 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
438 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 ...
-4
votes
1answer
58 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
101 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
540 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
113 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
73 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
125 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
53 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
215 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
368 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
141 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
206 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
13k 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
343 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
128 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
54 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
176 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
159 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
69 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
520 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
129 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 ...

1
2 3 4 5
62