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
0answers
60 views

Using Decorator Pattern For Debugging

So I keep being asked to add new metrics and log certain debug information to my current project. Now, as one would expect, this has start cluttering the code too much. From what I have read and seen ...
36
votes
9answers
6k views

When is it appropriate to introduce a new layer of abstraction into a class hierarchy?

Suppose I'm creating a game played on a 2D coordinate grid. The game has 3 types of enemies which all move in different ways: Drunkard: moves using type 1 movement. Mummy: moves using type 1 movement,...
1
vote
2answers
148 views

How to avoid type checking with Java/OOP in this situation?

I have a collection of animals (interface) which contains birds and cats (both also interfaces). I want to print out all the cats to the console and I am forbidden to use instanceof (I did not make up ...
2
votes
2answers
136 views

Builder Pattern: Is it acceptable to use “passing-by-reference” on Director methods?

For teaching purposes, I am trying to create a PHP implementation of a conceptual example of Builder Pattern: First of all, some products: class Product1 { private string $attribute1; ...
3
votes
3answers
150 views

How to clone an object graph and keep relationships of objects intact?

In my ASP.net core application with Angular 2+ client, I work with a complicated object graph. In the object graph I have some objects with references to each other. I have a simplification included ...
0
votes
1answer
60 views

How to keep components modular/independent in a layered architecture?

Lets say we have a layered architecture where A->B->C are three different layers. Function calls are passed from A to C and data is passed up from C to A. I think in this case A will have a reference ...
1
vote
2answers
74 views

Should database model POJO contain *entities* or *ids* when having 1:M, M:N relationships?

Though this seems less like a software engineering problem, IMHO it is actually about programming paradigms, instead of specific "how to solve this bug" questions... Say we have article, author and ...
3
votes
2answers
120 views

Abstract Factory: Can Client Class have an aggregation with the Factory?

After searching for some Abstract Factory examples using modern programming languages, I have some dillemas about the sensu lato of conceptual UML schema of Abstract, more specificly about the Client (...
3
votes
4answers
297 views

Do “avoid primitive obsession” and “use most abstract type as possible” contradict each other?

According to Is "avoid the yo-yo problem" a valid reason to allow the "primitive obsession"?, I should define "price" like this: public class Main{ private Price price; } ...
1
vote
1answer
121 views

What is the difference between simple factory and factory method?

I am a little bit confused about simple factory and factory method. My main difficult is the abrut difference between the examples code on the internet, even on wikipedia, where have lots of them, ...
0
votes
0answers
36 views

CK Metrics - Lower Complexity by Refactoring

I'm suppose to identify 3 CK metrics and the most appropriate class to refactor so as to increase encapsulation, modularity and reduce the complexity of the following project According to my ...
1
vote
0answers
36 views

How does a framework manager, broker or coordinator class handle pluggable extensions and make them run?

I'm trying to understand if there is a manager/broker/coordinator class in frameworks and I hope so, but what possible ways are in a framework to make it run the pluggable extensions and what the term ...
3
votes
3answers
120 views

confused with abstraction definition?

I have some years of oop programming experience,I though I know what abstraction is (using abstract class and interface), but I am confused with the definition that appear in a book which says: "The ...
2
votes
4answers
481 views

Unnecessary (?) ReadOnly fields in Interfaces

Under the context of dependency injection - that is, an interface has mostly one implementation - I took the habit of exposing via the Interface a bunch of fields which are never called by the ...
-3
votes
1answer
129 views

Python Code Design - How should I have used OOP?

Edit: My main question is how would you structure and design code to accomplish the project I describe below. Please try and think of this as a technical interview question and you have to describe ...
2
votes
1answer
63 views

No confident about pre/post conditions on LSP

I have some doubts about the practical way of violate or to not the pre and post conditions based on Liskov Substitution Principle. In the beginning, I have create the examples where first child ...
34
votes
6answers
8k views

Do you need to think about encapsulation if you can ensure immutability?

Encapsulation In object-oriented programming (OOP), encapsulation refers to the bundling of data with the methods that operate on that data, or the restricting of direct access to some of an ...
0
votes
1answer
66 views

Why does php not allow to decrease visibility of class properties and methods in the inheriting class?

Please consider the following code: class baseclass { public $hideme; public function getit() { return $this->hideme; } public function setit($value) { $this->hideme = $value; } } ...
2
votes
2answers
166 views

How do you do SOLID with Data Oriented Design?

As far as I know Data Oriented Design differs a lot with OOP. It encourages reusability of data, discourages polymorphism, etc. And because SOLID uses OOP a lot (especially Interface Segregation ...
5
votes
7answers
404 views

Fail-fast design vs. limiting constructor logic

In any programming task, my preference is to write fail-fast code. That doesn't seem to be too controversial. However, I've also seen many developers say that constructors should do as little as ...
-3
votes
0answers
168 views

Understanding the scope resolution operator in PHP language

On the php manual they define the scope resolution operator as following: The Scope Resolution Operator (also called Paamayim Nekudotayim) or in simpler terms, the double colon, is a token that ...
13
votes
3answers
5k views

How does encapsulation actually work?

I made the following diagram to show a typical separation of concerns as typically taught - Here ClassA indirectly uses ClassB via the ISomeInterface, of course ensuring it doesn't know ClassB exists,...
-3
votes
1answer
54 views

Where is it appropriate to implement the split_array method

I am writing an implementation of a binary search tree and in doing this I need a method that splits an array in two. I am unsure where it is appropriate to place this method. What I mean by "where ...
1
vote
1answer
104 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
340 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
172 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
183 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
166 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
4answers
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
78 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
953 views

Definition of “Behaviour”?

What is exactly meant when software-engineers talk about "behaviour" in contrast to "state" (Definition of "state")?
5
votes
1answer
136 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
65 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
67 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
84 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
98 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
201 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
157 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
349 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
274 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
66 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
138 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
124 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
150 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
65 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
155 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
202 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 ...

1 2 3 4 5 58