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
1
vote
1answer
97 views

Is designing a generic parameterized class with methods of it accepting higher order functions a functional technique that we can use in Java 8?

Recently I have asked this question: How do you rewrite the code which using generics and functionals in Java 8 and mixing oop and functional programming by using only object-oriented? on ...
5
votes
3answers
278 views

Is it true that “A Java Iterator is an Abstract Data Type”?

I'm trying to deepen my understanding on this, the only thing I know for sure is that Iterator is an interface in Java. I've been reading CS literature, for example here and here and looking for ...
2
votes
1answer
150 views

What are Java Interfaces used for? (multiple choice question)

I'm a beginner studying interfaces in Java through some quizzes and I came through this question: What are Java Interface used for? I can opt among one of the following three choices: A. They'...
1
vote
2answers
163 views

OOP: centralized vs decentralized approach

Suppose you have a client-server architecture structured with a Client class that asynchronously implements the Send() and Receive() functions. You also have a base Message class and several other ...
0
votes
1answer
34 views

Scaling inserting related optional objects to your collection

In PHP, you can have a collection as an array as a class property. This collection can have a function add that takes multiple (type-hinted) parameters, as such: add( Markup $markup, Style $style = ...
1
vote
2answers
128 views

Simple Snake Game in C++

I posted this question originally in Code Review, but then thought that I could possibly get more feedback about the design here. I just finished writing a simple Snake clone in C++ with the goal of ...
11
votes
3answers
2k views

Looking for an effective pattern to cope with switch statements in C#

I sometimes end up with services encapsulating the responsibility of doing some sort of business process for which there are several possible outputs. Typically one of those output is success and the ...
0
votes
1answer
72 views

Does the visitor pattern prevent the need to modify existing code when adding new data types?

From what I understand, the visitor pattern is supposed to solve the expression problem (described here), where a program needs to support performing multiple operations on multiple types, ideally ...
8
votes
3answers
924 views

Definition of “Behaviour”?

What is exactly meant when software-engineers talk about "behaviour" in contrast to "state" (Definition of "state")?
5
votes
1answer
127 views

Selectively exposing interface of inner members

I have a class called D2Array which represents a fixed-size 2D array. It's meant to be generic and it comes with quite its lot of methods: getting an element, setting an element, extract a whole row, ...
0
votes
2answers
55 views

Needs to understand the difference between boundary, controller, logical class types

As the title implies I am trying to understand the difference between boundary, controller and logical class types, which are used in the MVC pattern. I will do so using an example. Please consider ...
1
vote
2answers
60 views

Composite Design Pattern with unequal weightage

You have a video game in which upon killing final boss you get coins that get distributed based on whether you are: Person(individual) Group(consists of individuals or groups) If reward for killing ...
-1
votes
2answers
77 views

How to implement a different behaviour for a method without changing the interface?

I am creating a small project that implements an interface in Java. I am not allowed to modify the interface, which means I can't change the functions in my class that implements the interface. ...
-1
votes
1answer
96 views

Is it encouraged or discouraged to use interfaces simply to enforce consistency?

What do you think about using interfaces just for the sake of enforcing certain naming and patterns across your team? Other than that, it doesn't hold any practical value programmatically. I'm on ...
3
votes
2answers
194 views

Syntactic characterisation of extrinsic and intrinsic states

Gang of Four’s Flyweight design pattern introduces the concept of extrinsic and intrinsic state: The key concept here is the distinction between intrinsic and extrinsic state. Intrinsic state is ...
35
votes
10answers
11k views

Is it a good idea to have logic in the equals method that doesn't do exact matching?

While assisting a student with a university project, we worked on a Java exercise provided by the university which defined a class for an address with the fields: number street city zipcode And it ...
2
votes
1answer
126 views

Late inheritance, enforce subclass behavior in the future

A super class Transaction has two subclasses TransactionA and TransactionB. A Transaction is composed of multiple events that occur in time for a specific key (a file, a person, etc.). Depending on ...
1
vote
4answers
311 views

forEach over branching over null check?

I was watching Zoran Horvat's "Making Your C# Code More Object-oriented" on pluralsightpaywalled. And he says that instead of : if(obj != null) { obj.DoSomething(); } We should have a list that has ...
4
votes
4answers
258 views

How to find the classes in an object oriented project?

I'm a bit confused by some object-oriented analysis and design (OOA&D) concepts. In OOA&D, what recommendations should be followed in order to produce a viable conceptual Domain Model? How ...
-5
votes
1answer
65 views

How to organize the following code in a better way? [closed]

I've a class which performs an operation (say A). I've few logic which has to happen before A happens and few during A happens and few after A has happened. interface ILaunchInterface { public ...
0
votes
1answer
59 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
96 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
122 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
136 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
64 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
145 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
200 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
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
2answers
123 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
96 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
227 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
117 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 ...
7
votes
3answers
452 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
85 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
55 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
244 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
478 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
143 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
42 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
90 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
249 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 ...
1
vote
1answer
271 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
59 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
57 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
130 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
92 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 ...
19
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
116 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,...