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
1answer
63 views

How to detect class responsibilities? [duplicate]

Consider following class: public class Foo { public Foo() {} public void Bar(int input) { Console.WriteLine("Working on input ..."); switch(input) { ...
-1
votes
2answers
588 views

What is the name of this “query builder” pattern I am looking for?

I have a microservice I am designing for getting "Book" information, and one of the capabilities is to query Solr and fuse it with some DB results that I queried. I am looking for, what I am calling ...
1
vote
1answer
128 views

Create a common interface to use N libraries and define specific behaviours

I am creating a browser automation library that is capable of using Puppeteer(automates chromium) and Selenium(automates all major browsers), but the goal is to also be able to add more libraries in ...
2
votes
2answers
161 views

Implementing Classes as Coroutines?

most OOP languages implement a class as a garbage-collected reference. however, a task (coroutine) based implementation may offer several advantages over traditional object references: -- method ...
0
votes
1answer
83 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 ...
2
votes
2answers
164 views

How to design different moves of different pieces of a Chess game using OOP principles?

I am trying to design a Chess game where each piece of the game inherits from an abstract Piece class. The piece just does a few things: It tells which color it is (White / Black) It tells what type ...
2
votes
3answers
204 views

Calculating method with complex result

I have a method that calculates the price a certain vendor gets for an item. Simplified it checks whether we have a price for that specific vendor, if not check if we have prices for that specific ...
34
votes
7answers
10k views

Should I still follow “programming to an interface not implementation” even if I think using concrete class members is the simpler solution?

According to Understanding "programming to an interface", as I understand, I think I should depend on abstract class only. However, in some case, for example, Student: public class Student {...
1
vote
2answers
142 views

PHP - Enforce classes to have method with parameter/return value of `self`

SCENARIO I am implementing "command pattern"-like classes. Since they are so similar to each other in so many sense (e.g. functionally, their relation in domain problem, etc.), it is ...
0
votes
2answers
97 views

Designing a tiling grid

I am implementing a grid-like game. The initial state is shown here: +++===+++===+++===+++===+++===+++ | | | | | | | | | | | | +++===+++===+++===+++===+++===+...
28
votes
9answers
9k views

In OOP, isn't the 'protected' keyword required?

Some modern languages (e.g. Swift, Dart) do not support the protected access modifier keyword. Swift is a protocol-oriented language, but I've heard that Dart is a completely object-oriented language. ...
2
votes
3answers
248 views

UI Adapter Dependency on a Secondary (Driven) Port - Hexagonal Architecture

I am applying the Hexagonal Architecture (Ports and Adapters) to my system and I have noticed a dependency from my primary (driver) side adapter to the secondary (driven) side port. This doesn't seem ...
2
votes
1answer
125 views

Optimal design for improved performance of a simulation code

I'm writing a code for the Discrete Element Method where I have balls (spheres) and walls (planes) interacting with each other. Those simulations are run for billions of time steps, so performance ...
8
votes
3answers
1k views

“Depend on abstractions, not on concretions” what is the exact meaning of this term

I was reading SOLID principles on a website, in which for D - Dependency Inversion Principle it says: “Depend on abstractions, not on concretions” In other words. we should design our software in ...
1
vote
1answer
375 views

Single responsibility in python [duplicate]

The SOLID principle is supposed to be the underlying framework for object oriented programming. The "S" part stands for: "Single responsibility principle" which in wikipedia is defined as: A class ...
3
votes
1answer
76 views

How would I approach collecting statistic across a method call chain?

Let's say I have an processing pipeline. It receives a file, converts the file to data, interprets the data, and then persists it. At every step of this way, I would need to collect statistics, so I ...
-2
votes
3answers
277 views

Do functions make Java a functional programming language? [closed]

I have been struggling to understand programming paradigms. OOP is a paradigm with sole aim of modeling complex (real-world) systems, and it got me thinking: is OOP the only programming paradigm ...
3
votes
4answers
653 views

What are the advantages of a 'pure' object oriented language over a non-pure object oriented language?

My first programming language is C++. C++ is a multi-paradigm programming language. One of the paradigms C++ supports is Object Oriented Programming. I want to say I get the general idea and benefits ...
-1
votes
2answers
146 views

In TDD, should returning class of public method be unit tested independently?

Suppose that I have a class that is returned only as a byproduct of another "main" class. I am using a Test Driven Development (TDD) workflow. Should this byproduct class be unit tested independently ...
1
vote
1answer
61 views

c# xml import and validation with different document versions without XSD

Context: I have a case where I need to extend some existing functionality for loading a new version of an xml file into a system (new fields, some mandatory that were not mandatory before, etc). The ...
2
votes
3answers
95 views

How should I best structure my app when I want to sort a “parent” model by a property computed on another “child” model?

Question about OO-programming, functional programming, NoSQL, SQL databases, and software architecture Hi all, I am a intermediate-level self-taught programmer, and have been dying to get an answer ...
4
votes
3answers
283 views

How to adhere to the Open Closed principle in a procedural language like C

In Robert Martin's seminal 1996 article "The Open-Closed Principle" he presents an example in C which does not follow the principle (the DrawAllShapes() method is not closed for modification): enum ...
2
votes
1answer
3k views

Service layer returns DTO to controller but need it to return model for other services

Following this post https://stackoverflow.com/questions/21554977/should-services-always-return-dtos-or-can-they-also-return-domain-models and best practices in Software Arch suggestions by Martin ...
0
votes
1answer
61 views

How To Design Event Handlers With Different Parameters

I have an interface Event and a class Agent. I want to be able to write something like agent.handle(event). However, the classes that implement the event interface will all have different fields ...
-2
votes
2answers
70 views

Do python Objects also store their memory address?

In python documentation, I found that every object has a type, identity, and value. Does this mean that the object also contains/stores their memory address?? Or are they just created at some memory ...
0
votes
2answers
133 views

Should parent classes define methods using attributes of child classes?

I need to extend the parent classes of two child classes by adding shared methods to them. Starting with the initial definitions of the child classes: class ChildA(ParentA): pass class ChildB(...
1
vote
3answers
1k views

what is the difference between Object and Value in Python

I have been trying to find this answer but I could not find the proper explanation Some say that they are the same and others say otherwise I know for a compound object, The object will consist of ...
1
vote
2answers
100 views

Need good design: Anemic Model, Inheritance and Pattern Matching

I have Handler classes which accepts Queries and returns Results. Handlers is anemic. They accept input data bag and returns output data bag. Handlers can be many so I created common generic interface ...
18
votes
11answers
10k views

Need Good OOP Design For World and Countries Problem

I am currently working on problem with a chicken or egg first situation. Basically, I am designing a solution which goes like this: World is a collection of countries; Each Country has a name, flag ...
-3
votes
3answers
194 views

Detailed difference between Procedural Programming and Object Oriented Programming [closed]

I'm a newbie. Please give me a detailed (very detailed one) about these two types of programming that even I, a beginner, could understand. Their core differences, relevant things that I must remember,...
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 ...
39
votes
8answers
4k views

Do access modifiers matter? [closed]

The theory is that access modifiers improve code safety because they support encapsulation of internal state. When doing OOP, every language I've used implements some kind of access restriction. I ...
5
votes
5answers
406 views

Implicit reading/writing of state in OOP hurts readability, maintainability, and testability. Good way of mitigating this damage?

OOP makes state reads and writes implicit. For instance, in Python: class Foo: def bar(self): # This method may read and/or write any number of self.attributes. # There is no way ...
1
vote
1answer
232 views

Java - private static vs. public static

A wrapper class for storing primitive parameters which are initialized with values. Is it better to use public static or private static with bunch of getters and setters, for these constants? public ...
1
vote
2answers
319 views

Calling methods on objects VS. passing objects as parameters

Which is considered a generally accepted practice? class Image { public void decode(); }; //main Image image; image.decode(); vs class ImageDecoder { public Image run(Image image); }; //main Image ...
9
votes
5answers
311 views

Presentation Layer Accessing Business Logic

I've been reading a lot of material lately about DDD (business entity objects) and other common patterns in n-tiered(layered) architecture. One thing I have issue with is, most articles, blogs, ...
0
votes
1answer
131 views

Representing mathematical tree structures using software in a compact manner

In my work I frequently come across systems of interdependent equations. I have contrived a toy example as follows. The terminal values w, x, y and z are given: e(y) = A+B A(y) = x*log(y)+y^z B(y) =...
8
votes
3answers
519 views

Does it violate the Single Responsibility Principle if an object knows how to change itself?

I have worked with examples like a Player object which knows how to change its own state. Another example, is an Invoice object which knew how to calculate its invoice charges using an algorithm. ...
-3
votes
2answers
91 views

Seeking appropriate design pattern(s) to describe most function-based mathematical problems

I have been looking for a good, general design pattern to implement simple mathematical structures where functions have the following properties: know which parameters they contain, parameters are "...
2
votes
4answers
138 views

internal Repository that's only accessed via Service, but needed to be access via DI

I have a library that provides access to our content management. It consist of a public ContentService and an internal ContentRepository. The ContentService is public and Dependency injected through ...
0
votes
0answers
44 views

Where to put property change callback code so I can handle the previous value of the property without using something different than BindableBase?

I have this uncompilable code below, it uses the code in this answer. In it gv means "the old value of a group's name", where a group is a group of clocks, and a clock is a timer or alarm. It ...
4
votes
1answer
415 views

Delegate vs Forwarding in Java OOP

I'm reading some article about "prefer composition over inheritance", and heard about Forwarding and Delegation. After search for the different I found some source: https://en.wikipedia.org/wiki/...
-1
votes
2answers
64 views

OOP classes hierachies for aiding static checking justified?

upfront I develop software for big data applications of which use is beyond my control (it ends up with a user), but I am not a trained software developer. So I apologize for any wrong terminology. ...
1
vote
4answers
307 views

Do we always need to override equals/hashcode when crreating a new class?

When creating a new class, should we always override the equals and hashCode even if we don’t intent at that point to use the class with any Collection classes? Or is it better to wait till such a ...
1
vote
3answers
233 views

Downcasting in order to call method of subtype

Is it a good practice to have a list containing objects of derived types and then filtering it by type checking when need to call methods specific for one of the types? From what I read typechecking ...
2
votes
2answers
250 views

Field variable VS method variable

hey i have a difficult question. class DatabaseHelper { Database db; String defaultShema; public DatabaseHelper(Database db, String defaultSheme) { this.db = db; this....
4
votes
4answers
436 views

Object Oriented Design and Relational Databases: Where to place behavior that pertains to more than one tables?

I have been trying to learn Object Oriented Design, but I find it very difficult to model objects that access a relational database and do JOINs. For example, I am building a REST API, it has User, ...
1
vote
2answers
205 views

Is it better to encapsulate dictionaries in library code?

I work on (big) codebase that consists out of multiple modules that are all built on top of shared library. In this shared library, is it better to encapsulate dictionaries as return values, instead ...
2
votes
1answer
227 views

DTO Design in Depth

I'm extending an existing application, which has an attempt at a logical tier design, using DTOs, a Services layer (business logic), and a DAL. However, as I'm investigating more about DTOs, my ...
3
votes
3answers
914 views

Interfaces in Python, multiple inheritance vs. a home-made solution

I am writing a Python framework. In order to ensure a class has some properties, I make base "interface" classes like: class BananaContainer: def __init__(self): self._bananas = [] @...

1 2 3
4
5
60