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
2 votes
1 answer
224 views

Mapping complex objects to other similar complex objects

I am working on two applications that serve the same purpose. The first application is more feature rich and its types are more complex, but uses old technologies and will be retired. It will ...
vicch's user avatar
  • 129
5 votes
4 answers
2k views

If class B extends A, can we say that B depends on A?

Let's say we have 2 (Java) classes: class A {} class B extends A {} To me, saying B extends A and B is dependent on A are both true (but not equivalent) in this situation. My colleague, OTOH, says ...
TheJavaGuy-Ivan Milosavljević's user avatar
0 votes
0 answers
83 views

Best way in C# to share class implementation patterns between abstract base classes [closed]

I could also ask this question for Java, D or C++. I remember, I found this to be an artificial limitation in Java already 10 years ago. I am currently working with C# and appreciate advices here. It'...
ChrisoLosoph's user avatar
6 votes
4 answers
1k views

How to avoid init methods when 2 objects need the reference of each other?

According to https://softwareengineering.stackexchange.com/a/334994/432039, I know init is a code smell and should be avoided, and one of the solutions is to use a builder to hold the state first ...
wcminipgasker2023's user avatar
3 votes
3 answers
236 views

Handle hierarchical relationships between large number of enums

I am working on a C# project and I have a somewhat large number of labels (~100) that have some sort of relationships between one another. Here is a minimal dummy example that illustrates this: ...
evolved_antenna's user avatar
-2 votes
1 answer
114 views

Defining functions inside vs outside a class

Say I have a class with a function do_thing that is comprised of multiple steps, which themselves segregate into functions (first_process and second_process). At what point would this be considered ...
Tim Kirkwood's user avatar
2 votes
1 answer
125 views

Refactoring Processor classes

I am writing some python 3 bioinformatics software and was wondering about the best way to write it in an OOP format. I am pretty sure a lot of my classes are violating the SRP principle, but I'm not ...
Tim Kirkwood's user avatar
2 votes
6 answers
337 views

Do private members/methods inherently violate the open-closed principle?

Doesnt private members and methods inherently violate the open-closed principle? Given that private, protected and public modifiers are supported. I came across this many times in codebases where ...
Code Spirit's user avatar
25 votes
15 answers
18k views

How far can you push Object Oriented Programming?

A getter is a failure to design an object. It violates encapsulation which is a core principle of object oriented programing. Now please tell me, how do you design a libraries hash table collection ...
candied_orange's user avatar
15 votes
9 answers
5k views

In OOP, what counts as a "getter"

Note: I'm not looking for opinions on whether the authors of the article below are right or wrong. Mainly I'm looking for the exact definition of what they mean by getters, especially since I know ...
Ced's user avatar
  • 589
0 votes
2 answers
121 views

What is a good architecture / design pattern for giving multiple shared attributes in different combinations?

I have a need for many different objects to have various combinations of attributes. For a demonstrative example, a flaming dog would have a dog attribute, a flame attribute, and a tail attribute, ...
Fred Etingen's user avatar
13 votes
6 answers
10k views

Why use a special "Name" class (instead of just a string) for representing object names in C++?

Suppose we have an Instance class in a C++ program, which has a GUID/UUID, name, parents, children, and other properties which can be saved to or loaded from an XML file. The intuitive approach for ...
AcinonX's user avatar
  • 613
1 vote
1 answer
137 views

How to implement DMG (Game boy) cpu's register using OOP patterns/principles to max code reusability?

I-m looking to learn better use of OOP principles/patterns so I decided to start implementing at least the basics of a GB emulator (technical part is widely covered on diff sites). So I started with ...
Allende's user avatar
  • 125
29 votes
14 answers
10k views

Avoiding throw because we are not sure the exceptions will always be caught

I'm a junior in my company, and one of the coding rules they have is: "a constructor object must never fail" (i.e., never throw). So what if I give them an invalid parameter? Then, the ...
sayanel's user avatar
  • 399
3 votes
4 answers
220 views

Does interface segregation principle apply to configuration data holders?

If you have a class representing your applicative config file. Instead of injecting that config class everywhere, would it be good application of interface segregation principle to expose several ...
Calimero's user avatar
  • 141
-2 votes
4 answers
218 views

How do access modifiers actually help programmers? [closed]

So a 'fundamental' OOP principle is being able to control the access to various methods and fields from other parts of the program by making them public or private. The reason is so that you cannot ...
user1345541's user avatar
-3 votes
2 answers
171 views

Polymorphism with variable default argument count

I'm in the process of writing a library in Python, and I've run into a design problem concerning the use of polymorphism. I have an ABC with abstract method 'foo': class A(ABC): @abstractmethod ...
Jan van Wijk's user avatar
0 votes
2 answers
224 views

How to deal with boolean or enum variables used to decide code flow?

I am working on algorithm implemented in C++ that maintains several enum types. Say 3 to 4 enum types each with at least 4 different values. Plus the code maintains several boolean variables. The code ...
Mahesha999's user avatar
0 votes
2 answers
149 views

How to model a player playing a Blackjack game in OOP? [closed]

I am trying to write a blackjack simulation using OOP. I have written it in a non OOP way before, but now that I found out JavaScript has private properties now, I try to get familiar with it and ...
ksl's user avatar
  • 29
0 votes
3 answers
330 views

How to refactor "init()" into "physically make them two separate classes"?

According to https://softwareengineering.stackexchange.com/a/334994/432039, I know "init()" method is a code smell, and "physically make them two separate classes" is a way to ...
wcminipgasker2023's user avatar
0 votes
1 answer
159 views

Function objects with no state shouldn't be object oriented? [closed]

My question relates to this topic here: Are classes with only a single (public) method a problem? There I read in the comments often something like that: It is no longer object oriented. Because ...
Robin Kreuzer's user avatar
5 votes
2 answers
568 views

Associations and References in UML Class Diagram

Is it possible to have an association without explicitly indicating the reference attributes in the participating classes in the UML class diagram? For example, consider this example : We can see ...
John adams's user avatar
14 votes
5 answers
5k views

How to "Tell, don't ask" when 2 objects involves in the condition and the decision at the same time?

According to Explanation on how "Tell, Don't Ask" is considered good OO, I know the following is bad: if(a.isX){ a.doY(); } public class A{ public boolean isX; public void ...
wcminipgasker2023's user avatar
-3 votes
1 answer
105 views

Are methods part of objects? or only fields are? [closed]

I wanna be sure if objects "contain" methods just as they contain their fields. Also, when you use the term "object", are you talking specifically about its fields?
Kaiyou's user avatar
  • 11
-3 votes
1 answer
186 views

Should you default to using classes in C++? [duplicate]

I recently discovered the KISS and YAGNI principles which made me question my usage with classes because I use them constantly without really thinking about it and I realized my code could be much ...
Konjointed's user avatar
1 vote
5 answers
618 views

How are strings simultaneously objects and primitive data types in C#?

In C#, strings can be used like objects with methods, properties, and other features of objects. At the same time, strings are treated the same as primitive data types like int or float in numerous ...
AcinonX's user avatar
  • 613
0 votes
3 answers
244 views

Is "my method supposes to work with specific subtype only" a reason to avoid "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 as possible. However, I found that a situation ...
wcminipgasker2023's user avatar
2 votes
1 answer
162 views

How is $this provided in PHP?

I got a fundamental question about the $this keyword in PHP and how it is defined. Pracitcally, I know what it is and what it does. But I am interested in how it is provided / implemented? For example,...
tweekz's user avatar
  • 237
2 votes
3 answers
492 views

Should I still "replace conditional with polymorphism" if the condition is from dynamic load data?

I know there are already some questions about replacing if else with polymorphism, for example: Applying Replace Conditional with Composition in functional programming Is it wrong to use any type of ...
wcminipgasker2023's user avatar
0 votes
1 answer
123 views

Should I "introduce parameter object" for the case that the parameter is originally already a whole object?

According to Should we avoid custom objects as parameters?, for example, if I have an object to show: public class Student{ public int _id; public String name; public int age; public ...
wcminipgasker2023's user avatar
0 votes
1 answer
145 views

How to model in OOP interactions with entities in other systems?

Assume we are designing a typical bank account management system. Customers can have one or more accounts. Customers can deposit cash, withdraw cash or transfer money to another account (and, of ...
A. Darwin's user avatar
  • 109
4 votes
1 answer
164 views

Is there a proper term for a "closed class hierarchy?"

What I mean by "closed class hierarchy" is a set of known base/derived classes used only for an implementation of something with no public API, i.e., the classes are not meant to be derived ...
Paul J. Lucas's user avatar
1 vote
4 answers
458 views

What's the alternative to trying to inherit static methods?

I know you can't inherit static methods, and it seems the consensus is that if you feel like you need to, you're doing something wrong. However, I don't know what the alternative is in my case. Please ...
Andrew Dean's user avatar
0 votes
1 answer
117 views

Functional interfaces or decorator-like implementations [closed]

Consider Chess as an example. Say, we have a lot of domain objects that are alike, in this case chess pieces. I have two proposes to implementing the behaviour of chess pieces. Both uses the following ...
Daniel Birn's user avatar
-2 votes
1 answer
240 views

Making objects aware of their (consistent) IDs

Abstracted problem I would like to be able to quickly refer to some (most likely non-hashable) objects. At the same time, I would like them to be aware of their own identity. The 2-way search should ...
Etua's user avatar
  • 7
1 vote
3 answers
231 views

Java design approach for "duplicated" class that are identical, except the import sources are different

So I have two identical classes, say ClassA and ClassB. In both classes, they operate on the same kind of data classes, and the method bodies are exactly the same. The only difference is that the ...
kroger9's user avatar
  • 25
0 votes
4 answers
161 views

What is the advantage/disadvantage of returning a UnSubscribe class to Observer as opposed to just calling a UnSubscribe method of Observable?

There are two ways to provide a way unsubscribe in Observer Design Pattern. 1. Provide a simple void UnSubscribe method: public void UnSubscribe(IObserver observer){ // remove observer from List of ...
SamuraiJack's user avatar
0 votes
2 answers
135 views

Push and Pull Communication in object oriented: why Push style is not flexible?

I'm trying to learn Observer Design Pattern and I started to watch the series which belongs to codewithmosh called "The Ultimate Design Pattern Series". in the lesson which was about ...
Mehdi's user avatar
  • 29
0 votes
0 answers
94 views

By creating an architecture, it is better to have many classes that handles different scenarios, or a single one that handles all? [duplicate]

During my limited professional experience, I have been involved in microservices projects with a common structure: The Controller takes a request and validates it using the jakarta.validation....
Paul Marcelin Bejan's user avatar
1 vote
1 answer
161 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
2 votes
1 answer
398 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
144 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
313 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 ...
mountainred's user avatar
0 votes
2 answers
204 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
2 votes
2 answers
1k 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
877 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
914 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
-4 votes
1 answer
83 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's user avatar
  • 143
0 votes
1 answer
152 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
320 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

1
2 3 4 5
68