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
1 answer
98 views

Can DI without the dependency inversion be replaced by protected properties?

Many people come from frameworks that implement Dependency Injection and IoC containers for everything (in my case Angular 2+), so, this group of people will try to use dependency injection and IoC ...
Vitor Figueredo Marques's user avatar
1 vote
1 answer
86 views

In python when is absolutely preferable use a class than a module?

Python is the language I use most in this period. My background in Java Before start learning Python I have programmed in Java language. In Java all code is written inside the methods of a class and ...
User051209's user avatar
0 votes
1 answer
129 views

Separation of concerns: persisting complex types

I have the following module structure: core persistence extension In my core module, I have an interface: Handler. This interface has multiple implementations in the core module as well as extension ...
alturkovic's user avatar
3 votes
4 answers
284 views

Is a preferences editing GUI a good use case of a object deep copy?

A conceptual question... I have a XML configuration file used to set various behaviours in an application (colours, supressing help prompts etc). On starting the application, the XML is deserialized ...
jwilo's user avatar
  • 79
0 votes
2 answers
108 views

Appropriate design pattern for providing a default Argparse instance, eliminating boilerplate

I'm using argparse.ArgumentParser extensively; however, it comes with a lot of boilerplate to set up, and this is especially noticeable when you've got more than a few common arguments that probably ...
g_elef's user avatar
  • 19
1 vote
2 answers
269 views

Why access the attributes of a Python class by reference?

Attribute references and instantiation In this link, that is part of the official Python documentation, I have found the following information: Class objects support two kinds of operations: ...
User051209's user avatar
0 votes
5 answers
202 views

Comparing Java objects with different member variables

I have a base class "People" which two other classes inherit from: Employee and Student. The Student class includes a GPA (type double) and the Employee class does not. I have an ArrayList ...
Delta88's user avatar
  • 19
0 votes
1 answer
226 views

Why are sealed classes not allowed to be mocked?

Using Moq framework, it is not allowed to mock a class in C# which is sealed. Same goes for many other frameworks as well. But why is it not allowed?
Akshunya's user avatar
  • 111
-2 votes
1 answer
48 views

Is it possible a class method have the same name as an existing function? [closed]

Courtesy link: What Are The Specific Meanings Of The Terms: Functions, Methods, Procedures, and Subroutines? What's the difference between a function and a method? In the linked question: ...
Arunabh Bhattacharya's user avatar
0 votes
1 answer
122 views

How best to share common steps between services while allowing them to provide their own behaviour

I've started working on a C# codebase. There are three services which run the same set of steps of three kinds of objects, each returning IResult: public IResult FooService(Foo foo) { ... } public ...
hyperfiction's user avatar
0 votes
2 answers
247 views

Does Clean Code suggest avoiding all base class instance variables (include private instance variables)?

According to Why is Clean Code suggesting avoiding protected variables?, I should avoid protected variables because of the reason : "closely related concepts should not be separated into ...
wcminipgasker2023's user avatar
3 votes
4 answers
443 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
49 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
173 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
137 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
22 votes
10 answers
8k 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,260
2 votes
2 answers
286 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
230 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
102 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
157 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
246 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
251 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
172 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
181 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
225 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
95 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
88 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
74 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
68 votes
8 answers
14k 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
347 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
  • 21
1 vote
2 answers
253 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
118 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
1 vote
2 answers
222 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
146 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
64 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
242 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
52 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
536 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
12k 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
7 votes
5 answers
786 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
245 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
71 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
1 vote
1 answer
457 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 ...
Drealler's user avatar
0 votes
1 answer
84 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
46 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
211 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
727 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
339 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,007
0 votes
0 answers
59 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

1
2 3 4 5
68