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
2
votes
2answers
113 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
2answers
116 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 prices for that specific vendor, if not check if we have prices for that specific ...
32
votes
7answers
9k 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
1answer
70 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 desirable to ...
0
votes
2answers
95 views

Designing a tiling grid

I am implementing a grid-like game. The initial state is shown here: +++===+++===+++===+++===+++===+++ | | | | | | | | | | | | +++===+++===+++===+++===+++===+...
27
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
153 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
108 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 ...
6
votes
3answers
380 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 ...
0
votes
1answer
71 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
0answers
53 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 ...
-1
votes
0answers
27 views

How to make my email system more dynamic? (architectural design and oop question)

I am designing an email system for Jenkins to send out an email based on different stages of the pipeline. I am having trouble designing it in a way so its as dynamic and scalable as possible. ...
-2
votes
3answers
231 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
444 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
140 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
40 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
89 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
233 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 ...
0
votes
1answer
96 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
57 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
54 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
102 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
109 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
82 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
98 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,...
39
votes
8answers
3k 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
392 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
133 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
304 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
235 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
116 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
456 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
78 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
3answers
110 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
40 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
212 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/...
-2
votes
1answer
50 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
237 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
200 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
136 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
387 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
140 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 ...
1
vote
1answer
71 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 ...
1
vote
3answers
242 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 = [] @...
7
votes
4answers
667 views

Changing States from child through parent while obeying SOLID principles

I'm trying to practise following SOLID principles. I'm a bit puzzled about following example (which is a remodel/artificial example based on actual code, which i cannot post here): public class ...
1
vote
1answer
238 views

What can I do to make adding new concrete classes (of abstract/interface classes) easier across the code base?

A real (but simplified) example from the program that I'm currently working on. We have an abstract Request class and two classes that extend it: FooRequest and BarRequest. They both have dao's used ...
4
votes
2answers
262 views

C# How to combine types I don't have access to?

I have been developing a library with the help of another library. So what I have set up here is two classes sub-classing the library's classes for additional functionality. The problem comes in when ...
1
vote
1answer
96 views

OOP: Interface design when having objects embedded in parent classes

During the design of a small app I ended up with two possible design alternatives that both would work but, somehow, I feel one could be better than the other in terms of following OOP Principles, ...
1
vote
2answers
137 views

OO Design - Encapsulation question

Scenario Let's say that there is an entity in my domain called Shop. As a shop owner (user), I am able to create rewards that customer users will be able to exchange. It also could be possible to ...