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
0
votes
3answers
88 views

C# refactoring with inheritance

I have two classes which contains almost same method. How can I refactor this with inheriting one class by other class. class A{ public void run(){ // task 1 // task 2 // task 3 } ...
1
vote
4answers
83 views

Removing a base class from its according collection OOP

Lets say i have a zoo class, with a bunch of collections. The collections are giraffes, elephants, tigers etc. All animal types derive from the same interface or base class, lets call it IAnimal. So ...
-1
votes
1answer
41 views

Simple circular dependency between three classes

I have this basic design with a circular dependency. Is there any solution for this? The problem is that a Machine cannot be created if a Model for that Team has been submitted.
0
votes
2answers
192 views

Terminology: Classes that contain only methods [closed]

I am studying the programming language Kotlin, and I just came across the idea of a Data Class. I have a background in Java programming where classes can have fields and methods. I have heard ...
1
vote
3answers
119 views

Can two unique messages share the same name in OOP?

In this question, the asker of the question shows the following example (no Polymorphism is used): circle1.draw(); rectangle1.draw(); And the highest voted answer says the following: In your example,...
0
votes
0answers
35 views

What is the design of libraries like cairo and OpenGL called?

I'm not a software engineer, so sorry if the question is elementary. Usually, functions provided by libraries written in C receive a handle from the calling program. This handle directly (if it's a ...
3
votes
3answers
145 views

Decoupling and Command Pattern

I am working on some project to learn how to make bigger and better software (multiplayer game) and I found a problem about having in my code a design pattern Command Pattern and anti-pattern God ...
-2
votes
0answers
70 views

Replace switch case with polymorphism [closed]

I am using commandline library to parse command line arguments in C# program and this is how my code looks like. I want to get rid of this switch case statemen by using something like polymorphism. ...
0
votes
1answer
73 views

Are inheritance, abstraction and polymorphism regarded as association in OOP?

In the realm of OOP, inheritance, abstraction and polymorphism are basic concepts of the paradigm. On top of that, there also have the concept called "associations" which I understand is ...
-4
votes
0answers
32 views

PHP Building customer class with extends, am I doing it correctly?

I am trying to build my own customer class. Customer data is separated in 4 MySql tables. I am not sure if this is idiotic or not yet. The tables are securities, customer, address and contact. The 4 ...
22
votes
4answers
6k views

Visitor Pattern: what's the point of the `accept` method?

I'm trying to fully understand the visitor pattern. What I've learnt so far (correct me if I'm wrong) is: It's about adding operations to classes, without modifying the source code of those classes. ...
0
votes
2answers
78 views

Can other behavioral OOP design patterns be expressed in terms of Strategy and Template Method Patterns for behaviour parameterization?

I'm studying OOP design patterns in a solution-oriented way which I mean not concentrating just one pattern but with a comparative analysis like their combined or hybrid usages and equivalents in ...
-5
votes
1answer
104 views

Use Case Diagram for Vending machine

I want to create a use case diagram for a vending machine which has the following states: Accepts coins of 1,5,10,25 Cents Allow user to select products Coke(25), Pepsi(35), Soda(45) Allow user to ...
1
vote
4answers
175 views

Is thinking of an OOP object as a “small program” a good analogy?

I have read that we can think of an OOP object as a "small program" that send messages to other "small programs" (objects), but I am not sure if this is a good analogy. One reason ...
1
vote
5answers
321 views

Why OOP languages use the syntax “object.function()” to send a message?

In C++ and Java and many other OOP languages, in order to send a message to an object, you have to use the object.function() syntax, for example: myCar.start(); // send the start() message to the ...
1
vote
1answer
81 views

Design Patterns: Factory Pattern Vs. getInstance Inside Abstract Class

I'm working on an app where we need to use different authentication flows depending on how the user is accessing the app. I want to make sure that there is only one instance of the authentication ...
0
votes
1answer
75 views

Extension of classes - Where to put behaviour - How much direct-access is allowed

At this point i would exclude the inheritance.... So the question is about more like extend into a seperate class or into the class which should be extended, both play in the composition-league. So ...
1
vote
1answer
57 views

Object oriented service best practice when changing a methods behavior for given context?

I expect this is a common problem and/or pattern question for beginners to OOP. Somehow I find myself wondering again and wasn't able to find a decent answer. So at the risk of creating a dupe... What ...
3
votes
2answers
291 views

What does “common interface” mean in OOP?

I have seen the term "common interface" used a lot while reading books about OOP. For example, the book The Essence of Object-Oriented Programming with Java and UML says the following: ...
-4
votes
1answer
35 views

Dynamically assign attributes to objects from outside

In python the following code works perfectly fine. class Table: pass table = Table() table.fruits = ["apple", "orange"] But as soon as we check it out with some kind of ...
1
vote
4answers
262 views

Is checking the type of a variable antithetical to OOP?

As an example, in PHP you can run gettype($myVariable); to obtain the type of a variable $myVariable. Is such functionality antithetical to OOP principles?
-5
votes
0answers
25 views

How to use multiple pipe filters in Angular?

I need to filter list of object by some criterias: status, activity,position, category. I have decioded to create separated pipes: StatusPipe, ActivityPipe, PositionPipe, CategoryPipe. I confused if ...
7
votes
4answers
572 views

Why does C++ have classes?

The title is deceptive; the question is really "why does C++ have classes and not only structs?" Often, people ask why C++ has structs if they are functionally equivalent to classes. The answer is (...
0
votes
1answer
86 views

what is the correct OOP way to read/write binary data if meta information of how data is encoded is stored inside data itself?

I have a Buffer which wraps a stream of binary data. The first byte indicates order, either big endian or little endian, which is needed to unpack the data. class FooBuffer implements Buffer is ...
0
votes
0answers
21 views

How to support alternative behaviour at the end of a pipeline when the new behaviour is decided at the beginning?

Let's assume we have a few loosely coupled components that form a pipeline. At the end is an file generating component. A new requirement comes in that requires an parallel alternative behaviour for ...
4
votes
2answers
178 views

How to design a SOLID pipeline with different inputs

I regularly have the situation that I have some complex logic that I break into steps. For example an import of an Excel file where I need to apply some logic or a complex calculation that I break ...
0
votes
3answers
131 views

OOD vs MVC; Live Objects vs Everything in Database

How to make memory-efficient code, but still have all the possible code nicely encapsulated ? I have a feeling that the OO (object oriented) approach is more intuitive and the code is nicely ...
1
vote
2answers
35 views

What does this statement about implementing forwarding methods of components mean?

I can't wrap my head around this statement here: One common drawback of using composition instead of inheritance is that methods being provided by individual components may have to be ...
1
vote
1answer
62 views

Can a GoF Builder implementation be considered valid without an explicit getProduct()?

For studying purpose, I've tried to create a simple PHP implementation of Builder GoF (not the Joshua Bloch's one) inspired on this slide. The main goal of this example is to encapsulate the ...
1
vote
1answer
61 views

How to design a class holding information about a relationship between two interchangable objects

I'd like to design a class that holds comparison results about to objects. Given I have a class Thing and that Thing has a bunch of properties. Now I have an engine that compares Thing instances (...
1
vote
4answers
203 views

OOP design: how to find one Subclass object in an array of Superclass objects?

Say I have a Group object which maintains a list of its Members: private $members; Now the class Member has a range of subclasses such as OrdinaryMember and GroupLeader. Every group has precisely ...
0
votes
1answer
79 views

How to define values dependant on the derived type?

My base class must provide an interface to get a value that is dependent solely on the type of the derived class. I can think of two ways of implementing this: Solution A, virtual functions: class ...
3
votes
1answer
82 views

Should a service object be transient or persistent?

In a typical server software design, business logic will generally invoke "services" (such as a database or web service). When I design such a system, I tend to think of each service as a singleton ...
2
votes
2answers
207 views

OOP - How to identify inheritance abusage?

In looking for a simple heuristic to see when inheritance can be abused, I came up with the following hypothesis: If subclass B overrides method foo, but does not call base.foo(), it seems like ...
1
vote
1answer
43 views

Inheriting DBModels and UI Models from Domain Models

I made a pretty simple CRUD API to store customers and some related information in a database. My customer has 20 properties like Name, Telephone etc. that are all stored in an anemic domain model. My ...
2
votes
1answer
58 views

How to determine whether the postcondition of overridden methods is weaker or stronger if there is no return value?

To reiterate the question - what does it mean to have a weaker or stronger postcondition when overriding a method that only does side effects with another one that only does side effects? P.S. What ...
0
votes
1answer
94 views

Object Oriented Design of Callback Methods

Assume that there is a library and it provides an interface to its users in order to callback them. Users implement this interface and receive notifications from the library. Let's say, ICallback is ...
2
votes
2answers
134 views

How can I improve this design to achieve a more loosely coupled system and better testability?

My question I built an inverted pendulum on an Arduino using C (ie. everything was done procedurally). I'm trying to self study application design and would like to refactor my code into a more OO ...
3
votes
3answers
124 views

What is meant by “Polymorphism is the ability of an object to take on many forms”?

Based on many tutorials that I have read, the following is the definition of Polymorphism: Polymorphism is the ability of an object to take on many forms Now let's assume that we have an Animal ...
1
vote
6answers
317 views

In what ways is Polymorphism used (other than in arrays)?

I have read many tutorials on Polymorphism and all of them show examples of Polymorphism used in arrays, for example you would have an Animal (parent class) array, and its elements are Cat and Dog and ...
0
votes
1answer
111 views

Mixing IoC container use with “poor mans” DI

I'm finding the use of IoC containers to be quite the shift in my application design, and its for the better. I'm using a framework called injector that aims to mimic (albeit not entirely) the Guice ...
1
vote
3answers
125 views

Best way to Model Classes associated with other Classes?

I'm trying to make a sports stats app in Java/Android + Realm. I have the following classes: Season Player Matches I would like the Season to contain a "list" of all the players that played that ...
-10
votes
1answer
60 views

Find design issues via a class diagram? [duplicate]

Given a class diagram , how can we find design issues in it. I am not talking about the relationships it should be representing as they exist in the real world but i am talking about design issues ...
0
votes
3answers
147 views

How to find design defects by using a class diagram? [closed]

What are the design defects that can be spotted by using a class diagram, and how? I am not concerned about syntactical/ representational defects, but in things like the following: Do the classes/...
-3
votes
1answer
48 views

How to know if the UML class diagram design is good (well-planned) or not in java

I've learned the UML recently and I am trying to build a MonsterDuel system. However, there are a lot of classes in this project, and I am confused about the abstract class and its usage. Now, I have ...
19
votes
10answers
6k views

What is polymorphism if you can already have methods that are the same defined in different types?

I often read definitions for Polymorphism such as the following: Polymorphism is the ability to have objects of different types understanding the same message But the above definition also apply ...
4
votes
2answers
407 views

What's wrong with using a Singleton?

I'm working on a Python application in which there are two Singleton classes: App and Configuration. The former seems straight forward, only ever instantiate one App instance; the latter seems ...
4
votes
4answers
188 views

De-coupling business logic from POJO de-serialization design pattern

I've a JSON file which I'm trying to de-serialize into POJOs. public abstract BaseClass { private String baseClassField; abstract String execute(); } ClassA extends BaseClass public ClassA ...
-2
votes
1answer
87 views

should the join method be in the Course class or the Student class?

The rule I was taught: "the method should be in the Object that it is invoked on" a student joins a course => the join method should be in the Course class a player drives a car => car.drive(..) ...
1
vote
2answers
85 views

What goes on behind the scenes when data is passed through the use of interfaces?

I understand an interface is a contract and if a class implements that interface, it must define those abstract methods from the interface. What I don't understand is, how is data passed between two ...

1
2 3 4 5
60