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
3answers
110 views

Should child objects not know parents while in views/view code?

As of iOS 6, Apple thought Unwind Segues would be added to their layout/views. What this means is, when you're on the 7th view of a stack, you can pop back to any other one. For those of you pure OO ...
0
votes
0answers
100 views

“Best practice” or “design pattern” to group a class with “associated” classes in an object-oriented language

Sometimes a class A can have an "associated" class B such that the implementation of B depends on the implementation of A. For example, this can happen when B's objects are to be created by A's ...
0
votes
0answers
54 views

Best practice for organizing code with checks for enabled feature

For example our App have Access Groups feature which may be enabled/disabled for the User. So we would have multiple checking for feature status in different layers like: if ($user->...
1
vote
3answers
132 views

Should we consider immutability for local scoped variables

I have the following code: const string endPoint = @"foo{0}?pageNum={1}&itemsPerPage={2}"; const int itemsPerPage = xxx; InvoiceCollection response = await _apiClient .GetAsync<...
2
votes
1answer
111 views

Is this a valid GoF Adapter example?

After visit dozens of pages searching a "non-sockets-or-iphone-conceptual-example" of Adapter Pattern, I have found this one: Lloyds bank is an international bank offers services worldwide. For ...
2
votes
1answer
109 views

Is it a good software engineering practice to store libraries as attributes of objects?

Suppose I initialize a library, say, in python object - #filename: file_A import file_ class A(): def __init__(self): self.pd = file_.pd self.np = file_.np And suppose the ...
-1
votes
1answer
128 views

Pass ID or Object which has irrelavant details as RequestBody in Rest Call?

Situation: I am designing a REST API that needs one or more, potentially large objects to do it's work I am facing a decision to either Pass the large object by reference and have the API retrieve ...
-5
votes
2answers
39 views

Difference in UML

What is the differences between the Class and Actor in UML. Can I use an actor in use case diagram which is used as a class in a class diagram?
-1
votes
1answer
83 views

Difference between objects and data structures?

So I was reading https://hackernoon.com/objects-vs-data-structures-e380b962c1d2 and I stumbled upon this quote : "A Person data structure has a first name, last name, and phone number. A Person ...
1
vote
1answer
148 views

Can Value Objects create their own value?

Let's say you have a username value object which has formatting rules e.g., class Username { private $username; public function __construct(string $username) { // thrown an ...
37
votes
10answers
7k 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
169 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
164 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
163 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 ...
1
vote
2answers
81 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
184 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
332 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
221 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
42 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
43 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
135 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
507 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
132 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
86 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
129 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
184 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
420 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 ...
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
57 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
127 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
431 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
181 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're ...
1
vote
2answers
199 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
340 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
5answers
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 ...
1
vote
1answer
96 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
1k views

Definition of “Behaviour”?

What is exactly meant when software-engineers talk about "behaviour" in contrast to "state" (Definition of "state")?
5
votes
1answer
142 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, ...
-1
votes
2answers
142 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
69 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
92 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
355 views

Syntactic characterisation of intrinsic and extrinsic states

Gang of Four’s Flyweight design pattern introduces the concept of intrinsic and extrinsic states: The key concept here is the distinction between intrinsic and extrinsic state. Intrinsic state is ...
37
votes
10answers
12k 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
160 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
833 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
293 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
69 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 ...

1 2
3
4 5
60