Skip to main content

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
3 votes
4 answers
491 views

Does "declare the most abstract type" increase coupling actually?

According to Why define a Java object using interface (e.g. Map) rather than implementation (HashMap), I know I should declare the most abstract type possible, so for example: public interface Fruit{ }...
wcminipgasker2023's user avatar
1 vote
1 answer
60 views

Should I combine use cases related to viewing?

When I did a small project in school about writing a document for Online Auction System in OOAD (Object-oriented analysis and design) courses, I had trouble with multiple Auction viewing use cases ...
Đặng Quang Huy's user avatar
0 votes
3 answers
200 views

Is "the boolean value is from dynamic loaded data (eg:user input, database)" a reason to use boolean parameter?

I know there are some questions about boolean flags: Is it wrong to use a boolean parameter to determine behavior?, Multiple boolean arguments - why is it bad? which indicates the following code is ...
wcminipgasker2023's user avatar
2 votes
2 answers
144 views

What is the threshold of "usage" of a parent class member that should move to child class?

For example, for base and child classes, if all child class need a class member, eg: baseHp, which represents the base hp to calculate the actual hp of monsters in a game: public class Monster{ ...
wcminipgasker2023's user avatar
23 votes
10 answers
9k views

Shouldn't deep copy be the default, not shallow copy?

If you have an OO language, where every object always has a copy method, shouldn't that be deep copy by default? In most languages I know, such a copy method is shallow, since a shallow copy is more ...
Mecki's user avatar
  • 2,350
2 votes
2 answers
346 views

In "Liskov Substitution Principle", are "Preconditions can't be strengthened in a subtype" & "Postconditions can't be weakened in a subtype" the same?

According to Is this a violation of the Liskov Substitution Principle?, as I understand, the top answer currently says the code below is violating "Liskov Substitution Principle": public ...
wcminipgasker2023's user avatar
0 votes
2 answers
238 views

Is circular referencing required in this situation?

class ItemList { constructor() { this.list = [];//list holds many instances of Item Class } removeItem(id) { //...search for item in this.list, remove it } } class Item { ...
Tyler Del Rosario's user avatar
-1 votes
1 answer
244 views

Alternatives to using mock libraries such as Mockito in unit testing

Typically, when writing unit tests I tend to need to stub out collaborators and also mock some behavior in one or more of the collaborating objects. Say if I am testing a Service that is using a Dao, ...
oligofren's user avatar
  • 107
2 votes
1 answer
205 views

Did the term "decorator" originate with OOP design patterns?

The Decorator pattern allows behaviour to be dynamically added to an existing object, effectively "decorating" it with new behaviour. While the pattern as formalised and named seems to have ...
Iain Galloway's user avatar
1 vote
2 answers
422 views

For more than one parameter, when NOT to introduce parameter object?

I know there are some questions about "Introduce parameter object", eg: Is "Introduce Parameter Object" actually a good pattern?, Should we avoid custom objects as parameters?, ...
wcminipgasker2023's user avatar
2 votes
3 answers
262 views

How do you decompose big object for testing?

I have a package that provides an object with quite a lot of features owned by it. Let us say the object is an HTTPServer, and when the user initializes it by providing config and a request handler ...
Bimo Adityarahman's user avatar
0 votes
2 answers
198 views

For non-container classes, are "better naming" and "ready for commented codes" good reasons not to declare the most abstract type?

According to Why define a Java object using interface (e.g. Map) rather than implementation (HashMap), I know I should declare the most abstract type possible, but the question is about template class ...
wcminipgasker2023's user avatar
5 votes
4 answers
3k views

Are "need to call objects in parent object" and "avoid circular dependency" reasons to avoid "Tell, don't ask"?

According to Explanation on how "Tell, Don't Ask" is considered good OO, I know I should avoid get the state of an object and then decides the actions to take to that object, eg: Bad: ...
wcminipgasker2023's user avatar
2 votes
3 answers
241 views

Is it necessary or "class obsession" (opposite to primitive obsession) to create classes for non-business fields?

I know there are some posts talk about primitive obsession : When is primitive obsession not a code smell?, Is "avoid the yo-yo problem" a valid reason to allow the "primitive obsession&...
wcminipgasker2023's user avatar
2 votes
1 answer
268 views

In poltergeist, whats wrong with "solely to trigger or initialize several other objects"? Isn't it is a good use of encapsulation and reuse?

After reading What differentiates function objects from poltergeists?, according to the definition of poltergeist, I still don't understand why would "poltergeist" be a bad pattern: A ...
wcminipgasker2023's user avatar
0 votes
2 answers
143 views

Where to put factories that depend on the application layer?

I am a frontend developer (currently working with Vue and TS), and I have been searching for better organization of the frontend code and recently I got to know DDD a bit. I know DDD is mostly used ...
Bernardo Benini Fantin's user avatar
0 votes
2 answers
148 views

How to structure a cart with cart products object

I am new to DDD and I am having trouble structuring an object. I have a cart, where I can add products to it. Each product has some properties like image, title, price, etc. Whenever a product is ...
Bernardo Benini Fantin's user avatar
0 votes
1 answer
136 views

REST - Adding a new field

I have an object with fields like ID, CODE, NAME, etc., and it has its own database table with each field. And I am working on implementing the REST API for this object. I want to expose all these ...
Arpit Jain's user avatar
71 votes
8 answers
16k views

When to *not* use SOLID principles

Coming from a math background, counterexamples are equally, if not more, helpful to me for understanding concepts than examples. I've seen many, many examples of when and how to use the SOLID ...
Derek Allums's user avatar
1 vote
6 answers
414 views

How encapsulating what varies can help us?

I have a question about encapsulation and I read these two topic (this & this) but I got more confused. I've been reading Head First Object-Oriented Analysis and Design book and I'm trying to ...
Mehdi's user avatar
  • 29
1 vote
2 answers
1k views

MVVM: How and should I expose view models' models to other view models?

Many times while writing MVVM apps in C# I've come across this sort of problem where I need to expose the model in a view model so that I can get it in another view model and do something with it. ...
aelsi2's user avatar
  • 21
2 votes
1 answer
129 views

OO vs FP: What is a good approach to understanding if heavy wrapper classes should be used?

Consider a processing system which ingests objects from an external source and performs extensive processing. One example could be objects detected by a computer vision system which are then fed into ...
panlex's user avatar
  • 265
2 votes
2 answers
360 views

Composition over inheritance: how data are accessed in the composition case?

I've been reading this Wikipedia article Composition over inheritance. It gives a code example of inheritance first, and then a code example of composition. In case of inheritance there are data that ...
Andrew Savinykh's user avatar
0 votes
1 answer
160 views

Is "Wrap child class operation into a function, then return the object, in order to declare most abstract type" necessary or over-engineering?

According to Why define a Java object using interface (e.g. Map) rather than implementation (HashMap), I should declare the most abstract type as possible. However, in some cases I remember, ...
wcminipgasker2023's user avatar
1 vote
1 answer
69 views

Is using an UId to hash Mutable Entities an anti-pattern?

In the context of an object-oriented language, such as Dart, I have an abstract entity which has a single property called id (which is incrementally uniquely generated to make sure there are no-...
Fabrizio's user avatar
  • 115
0 votes
4 answers
254 views

Single responsibility principle - Classes with operator overload

I've been reading a bit through Clean Code and I came across the Single Responsibility Principle. The principle states that every class should have only one responsibility. An example taken from ...
user8469759's user avatar
0 votes
0 answers
77 views

How to handle multiple-state domain object?

Let's take an example of Order. An order can have the state new, canceled, shipped, or processing. The new order can be processed. The new order can be canceled. The processing order can be shipped. ...
Ngọc Nguyễn 's user avatar
5 votes
2 answers
2k views

What is the difference between detailed design and design for construction?

I am currently reading Code Complete. And I was confused when the author in one case uses the term "detailed design", and in the other "design for construction". What is their ...
user avatar
17 votes
8 answers
13k views

Why is "diamond problem" a problem? Why doesn't the child simply call both parent's methods sequentially? Why is a thing with solutions a problem?

I know there have been many post about diamond problem, one of it: Why do you reduce multiple inheritance to the diamond problem?. But I'm not asking what it is or what is the solution of the problem. ...
wcminipgasker2023's user avatar
8 votes
7 answers
1k views

Is "avoid feature envy" violating "open closed principle"?

After reading What is a" feature envy" code and why is it considered a code smell?" I know the following code is suffering from "feature envy": public class Garden{ ...
wcminipgasker2023's user avatar
2 votes
1 answer
437 views

Domain models: Can they be an abstract class

When talking about having a rich domain model successfully, in real applications, it needs to, somehow, access some abstraction of complex functionality (instead of being a row state calculator the ...
Vitor Figueredo Marques's user avatar
0 votes
1 answer
78 views

Creating Controllers and Repositories without corresponding Models

I have to create a system to interview people on a few topics where they have to answer both objective and discursive questions, where questions may change between interviews. I structured the ...
Akari Oozora's user avatar
2 votes
1 answer
1k views

Clean architecture - how to manage use cases that depends on external apis

How to apply clean architecture concepts in a software that depends on External APIs. Example: A business that offers some kind of subscription to its users. Its convinient to store some subscription ...
Rafael Alencar's user avatar
0 votes
1 answer
541 views

Mapping list to another list dynamically

I had an idea for a piece of software using .NET C# as technology. Basically, in my idea Im thinking of using reflection to do the mapping between a class to another class using interactivity with a ...
Nmaster88's user avatar
  • 167
0 votes
0 answers
48 views

Should I add new method to the interface to use it more commonly or just separate the new logic completely

I have a CouponReservationService in an e-commerce project. It is called when a coupon is reserved to be applied to a basket. It checks that whether the coupons are already reserved. If they are ...
Ismail Yavuz's user avatar
1 vote
2 answers
245 views

Is "declaring most abstract type" suffers from the same problem as "primitive obsession"?

According to Why define a Java object using interface (e.g. Map) rather than implementation (HashMap), when creating objects, I should declare the most abstract type, eg : Map hashMap=new HashMap(). ...
wcminipgasker2023's user avatar
4 votes
9 answers
1k views

Can a Domain Object always be "completely ignorant of persistence" and yet still possible to persist?

Domain Object, while not necessarily a design pattern, can at least be considered as a design "concept", and one of its points is: https://wiki.c2.com/?DomainObject Domain objects should ...
The_Sympathizer's user avatar
3 votes
2 answers
382 views

When refactoring many functions that share state in to a single class, how can you avoid writing an "escort" class?

This well-known article criticises Java on the basis that it does not allow you to write functions that do not live in a class. This flaw forces you to write classes with names that look suspiciously ...
J. Mini's user avatar
  • 1,017
0 votes
0 answers
69 views

Decoupling a Configuration API in an Embedded Framework

In my embedded project I am designing a framework that allows the user to create widgets at compile time. All widgets must provide the same base functionality. Further, there are multiple widget ...
nowhere_'s user avatar
10 votes
9 answers
4k views

What is an immutable object anyway?

The most popular answer is - it is an object whose state does not change after creation. What does it actually mean? My understanding is that any method call on the object should give the same result. ...
kan's user avatar
  • 402
0 votes
0 answers
147 views

How to handle dependency injection in a library to avoid frequent breaking changes?

Let's say I have a C# .NET library with the following classes: public class FooService { private readonly IDependencyA a; public FooService(IDependencyA a) { this.a = a; } ...
srk's user avatar
  • 127
2 votes
4 answers
1k views

My concrete classes only have a constructor. Everything else comes from an abstract class. Is this bad practice?

I think that I've taken the Open-Closed and Single Responsibility principles too far. Previously, I had one huge static class containing every method that has C# talk to stored procedures on my SQL ...
J. Mini's user avatar
  • 1,017
0 votes
2 answers
131 views

Services: Which structure is a better idea?

I'm designing my service layer for a GraphQL API and there are many situations in which I can't decide if code relating to a table should belong in it's own class, or the class that 'owns' the data. ...
J Doe's user avatar
  • 101
0 votes
0 answers
213 views

Abstract base classes and mix-ins in python

In the python docs, I read this about the ABC (abstract base class) meta class: Use this metaclass to create an ABC. An ABC can be subclassed directly, and then acts as a mix-in class. I don't come ...
henryn's user avatar
  • 111
1 vote
4 answers
2k views

I wrote a class with "init" method. Should I call it from other class methods? Or leave it to the object user? (Code Design)

I have a java class with an init method. It's different from the constructor. The constructor just initializes the variables/fields. The init method connects to a database and performs some ...
joker's user avatar
  • 121
0 votes
2 answers
300 views

How to refactor this tightly-coupled method and (mostly) preserve its encapsulation?

I have recently encountered this problematic method (minimal reproducible sample in C++ but this question aims to be language agnostic past the syntax): void MyObject::twice_bind_cycle() { _bind1()...
goober's user avatar
  • 117
-1 votes
1 answer
77 views

Optimal OOP security for PubSub - Should mutual consent be required?

I am implementing the Publish-Subscribe pattern. I have class Broker and interfaces IPublisher, ISubscriber. interface IPublisher { broker: Broker; publish(channel: Channel, data: object): ...
Michael Moreno's user avatar
-1 votes
1 answer
132 views

How to extend many types of classes, keeping some of their methods?

I have a base abstract class that have many methods, and multiple subclasses that extends it and implementing the methods. I have another type of subclass that need to wrap the subclass and extend ...
user1941348's user avatar
1 vote
1 answer
71 views

Querying objects in a list by class type vs string identifier - Best practices

I have a class Character who has a list of Spell objects that he can cast. abstract class Spell { name: string manaCost: number abstract cast() { ... } } class InvisibilitySpell extends ...
Michael Moreno's user avatar
2 votes
2 answers
145 views

OOP Best practices: Is there any reason to separate out Factory functionality from an abstract base class?

Consider the following python3 code: from abc import ABC, abstractmethod class Food(ABC): _food_factory_map = {} _recipes = {} @classmethod def getFood(cls, foodName): return ...
raghavj's user avatar
  • 29

1
2
3 4 5
68