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

Is this a 'proper' use of a trait in PHP?

In Laravel 5.6 an Illuminate\Database\Eloquent\Relations\BelongsTo relation was given the ability to support default models. This allows a model that will be returned if the relationship is empty. ...
flyingL123's user avatar
0 votes
4 answers
153 views

Should a class which has a method to create object A also implement a method to delete A?

For example, suppose I have a class to create a button with specific styles common to my app: class ButtonFactory{ public: static Button* createAppButton(std::string st,int font size){ Button* ...
ocomfd's user avatar
  • 5,712
0 votes
2 answers
759 views

Achieving Liskov-compliant contravariance in method arguments in C#

Trying to practice LSP, the following is not really clear to me: Liskov requirements (some) -There must be contravariance of the method arguments in the subtype. – There must be covariance ...
Ezoela Vacca's user avatar
0 votes
2 answers
9k views

Design Pattern for a "manager" type of class

I have a class that I usually end up calling XManager. This class usually acts a dispatcher. Where it will read a config and do what the config says. Assuming that I have the following class ...
lilott8's user avatar
  • 111
0 votes
2 answers
197 views

Where Should I put data related to more than one entity?

Right Now I design Time & Attendance System. If I have the following entities : Shift (Id,Name,start_time,end_time, ...etc) EX :1,Morning,08:00,16:00 WorkSchedule (Id,Name,Type,...etc) EX :1,...
Anyname Donotcare's user avatar
0 votes
1 answer
121 views

Static field injection into subclasses

Say that I have a C++ class with some fields with static storage duration, call it class A. Is there some way to use inheritance to "inject" these static fields into classes which derive from class A?...
MattyZ's user avatar
  • 113
0 votes
1 answer
383 views

Is this an example of Composition or Aggregation?

I understand the concept behind Composition ('has a') where the contained class is destroyed upon termination of the container class. Likewise, I get Aggregation which is a 'looser' relationship ...
user3396486's user avatar
0 votes
1 answer
119 views

Abstract class vs relation between classes

Searching for simplest solution where a User can order an item. If someone purchases an item he will have one address. Which then is the invoice and shipping address. But he could add another address ...
caramba's user avatar
  • 141
0 votes
2 answers
73 views

Trouble handling constraints for the input of a method

I'm looking for advice on how to handle constraints on the input of a method. I have a method that only works if the input argument(s) fulfill certain constraints. If the method is called on input ...
Kjara's user avatar
  • 272
0 votes
1 answer
319 views

Is it wrong to call a "non-static nested class" an "inner class" in Java?

I was reading this question in SO, and it contains the following: A non-static nested class (sometimes incorrectly referred to as an 'inner class') (...) And it confused me. At 350+ upvotes, I ...
Mindwin Remember Monica's user avatar
0 votes
1 answer
286 views

When to use "is a" or "has a"? [closed]

In my node.js application, I have a queue class which has push and pop methods and a data property. I have an Event class which handles an event and pushes it on to the queue. If I think object ...
Jafar Rasooli's user avatar
0 votes
2 answers
256 views

OO design patterns similar to Drupal's hook system?

The core of the CMS Drupal is not based in object-orientation in version 7. For writing pluggable modules, it has a "hook" system, whereby you can alter the behavior (by altering passed data) for ...
user1936's user avatar
  • 652
0 votes
2 answers
484 views

Mermaid problem (OOP) [closed]

A Mermaid is half fish and half human. It has upper human body and lower fish body. When under water its upper part swims like a human while its lower part swims like a fish. Please explain how can it ...
ar27111994's user avatar
0 votes
1 answer
119 views

Upgrade object in PHP

I cannot find information on this anywhere so I assume it doesn't exist. It makes much sense for me for such functionality to exist and I want to ask whether it actually does and I am wrong in my ...
php_nub_qq's user avatar
  • 2,224
0 votes
2 answers
157 views

How to ensure a new Unit Test is for the correct Test Case? [duplicate]

When writing a unit test for a scenario believed to be already covered, ie, the first run of the test would be green, what is a good guideline to ensure that it is in fact testing the proper test case,...
Kindread's user avatar
  • 103
0 votes
2 answers
2k views

What is the rule for nested loop code?

I am new to programming and currently learning Java from Stanford free learning course. There was this assignment that I had trouble translating my algorithm into code. I feel like I have a ...
Sadij's user avatar
  • 11
0 votes
1 answer
2k views

Splitting single Class into multiple Classes

I am writing automated test scripts with Selenium Webdriver (Python) and I try to follow the correct programming practices, specifically the Object Oriented methodologies, where possible. At the ...
Eugene S's user avatar
  • 119
0 votes
1 answer
81 views

Condition before statement or statement in condition

I've come across this problem a few times: Is there any "programming rule" for checking for an condition (error checking for example) before you want to do execute code, or only execute the code when ...
Bas's user avatar
  • 175
0 votes
1 answer
156 views

Why is it said that a class represents an abstraction? [closed]

I think that abstraction represents only the essential things needed for the purpose as there are so many unnecessary properties. So why is it said that a class represents an abstraction?
Souhardya Mondal's user avatar
0 votes
1 answer
1k views

Interface or boolean?

I have a CustomObject class which has the abilities like being Clickable, KeyPressable and Movable. I created interfaces: IClickable, IKeyPressable and IMovable and make different CustomObject classes ...
ctulu's user avatar
  • 103
0 votes
2 answers
1k views

In plain English, what is an object model? [closed]

I read about objects models on Wikipedia, but it is too abstract to really make much sense to me. Can someone explain what an object model is in plain English?
chopper draw lion4's user avatar
0 votes
1 answer
983 views

Intermediate results as variables or only base values?

I have a object which has a few base variables (integers as example) and one intermediate variable for further processing. The intermediate variable can be calculated from the base vars. Now the ...
Nova's user avatar
  • 103
0 votes
3 answers
148 views

OOP: relying on protected properties in a class-subclass contract

I'm coding in Python, but the question seems independent of programming language. I have a class that represents some system check: class Check: @abstractmethod def run() """ You have to ...
Eugene Koval's user avatar
0 votes
1 answer
362 views

What should be in a PIMPL?

I am kinda trying to implement a windowing library in C++, the circumstances are forcing me to implement it all myself, that's not the point of this question however. My question is: What should be ...
LaVolpe's user avatar
  • 213
0 votes
1 answer
321 views

Method Parameters Ordering [closed]

I was recently changing a method to add in an additional parameter, and I couldn't help but wonder if there were "best practices" or "generally accepted rules" in deciding what order parameters of a ...
DoubleDouble's user avatar
0 votes
1 answer
1k views

Efficiency of getters/setters with database performance

I'm currently in the process of refactoring a very old personal project of mine, which used procedural PHP-in-HTML code. I'm modernising it as a learning project, using OOP where beneficial. I ...
Roy's user avatar
  • 513
0 votes
3 answers
358 views

Structuring an application that reads from a .properties file

I have a Java app with three classes: Foo, Bar and Baz. All three depend on a bunch of what are currently constants defined in each class in order to determine how to run. On top of that, Baz ...
Patrick Collins's user avatar
0 votes
3 answers
685 views

In which object should I implement wait()/notify()?

I'm working in an Android project with multithreading. Basically I have to wait to the server to respond before sending more data. The data sending task is delimited by the flag boolean ...
Christopher Francisco's user avatar
0 votes
3 answers
976 views

Reason to treat internal class variables and functions inside a class as "separate" entities

Note: there is a similar question that addresses my subject: Better style for member variables? ... but that question does not address "dealing with large legacy code base and comprehension of ...
Dennis's user avatar
  • 8,217
0 votes
1 answer
845 views

Read-only class properties [duplicate]

When is recommended to use read-only properties -- if the language allows me? Are public read-only properties meant to replace getter methods or at least the Magic Methods like what is available as ...
Mahdi's user avatar
  • 1,993
0 votes
1 answer
693 views

Objects as parameters: Is there a simple way that explain this? [closed]

I tried to understand how objects can be passed as parameters but it was difficult for me. How can we pass an object as a parameter to a method of another object? I need to understand the idea behind ...
user3314958's user avatar
0 votes
2 answers
1k views

When to decide to introduce interfaces (pure abstract base classes) in C++?

Assume that you are developing a functionality and are 90% sure that the implementation class will stay alone. If I was in this position in Java I would probably not use the interface right now to ...
Honza Brabec's user avatar
0 votes
2 answers
777 views

Object Orientation done right with PHP [closed]

I've started to work with web development using PHP as server side programming language. In that time I didn't know the benefits of object orientation and had a hard time trying to write more ...
user1620696's user avatar
  • 4,867
0 votes
1 answer
518 views

How can my code structure be improved? [closed]

I am looking for advice on the neatest way to structure my code. class Password { private string cipher; Password(string cipher) { this.cipher = cipher; } public string ...
Ayrx's user avatar
  • 248
0 votes
3 answers
509 views

Should a service use session information?

As an example, if I have a Post service and have a method to retrieve all posts for the logged in user, is it OK to have a findPosts() method that uses an injected Security service to get the user ID ...
Rocket04's user avatar
  • 1,076
0 votes
3 answers
3k views

Avoiding coupling

It is also true that a system may become so coupled, where each class is dependent on other classes that depend on other classes, that it is no longer possible to make a change in one place without ...
Seralize's user avatar
  • 464
0 votes
1 answer
141 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
0 votes
2 answers
150 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
0 votes
2 answers
236 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
0 votes
2 answers
194 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
0 votes
2 answers
201 views

Is there a UML symbol representing instantiation? This one doesn't seem to be one

The following figure comes from https://spring.io/guides/topicals/spring-security-architecture I refer to it as a "figure" rather than a "diagram" as I'm not sure if it is. the ...
JJJohn's user avatar
  • 111
0 votes
3 answers
1k views

How to handle a new method in the interface that is not applicable for all classes?

I am faced with an interesting OOD problem: I have an interface with 3 methods: interface TestInterface { String action1(); String action2(); String action3(); } and 3 classes that ...
Zed's user avatar
  • 117
0 votes
2 answers
813 views

Inheritance/Composition VS "Direct Injection Construction"

my following example seems to go into the direction Inheritance VS Composition. But that's not, what i want to ask. I see the concept Inheritance and Composition on one side and the alternative, which ...
Robin Kreuzer's user avatar
0 votes
1 answer
114 views

Time consideration in multiplicity of classes

In the following image, regarding a CD shop that rents its music CDs. My question is regarding the correct multiplicity of X. I can think of several possibilities for X: X= 1..1 as each copy of ...
Karl 17302's user avatar
0 votes
2 answers
978 views

How to implement resources of a REST API as classes?

I need to access and process different resources from a REST API. For this I've come up with two different approaches: Approach 1: Create one class per resource, that handles accessing the data from ...
sininen's user avatar
  • 129
0 votes
3 answers
157 views

Handling Objects with Same Output but different required inputs

I have various types of financial securities. Each one of these securities shares a common set of methods. For instance, they all pay some amount of cash interest between two dates. Each security has ...
cpage's user avatar
  • 57
0 votes
1 answer
115 views

Should I define a separate interface for clarity rather than implementing Supplier<T>?

Let's say you have to meet some prerequisites before doing something. For that, I think implementing Supplier<Boolean> is a great candidate since it's widely used, and quick to understand. But, ...
eca2ed291a2f572f66f4a5fcf57511's user avatar
0 votes
3 answers
1k views

How should an abstract class require a value that will be constant for each subclass?

Let's say I have an abstract class A exposing a method called getE() which returns an object of type E which is an enum. The value returned by getE() will be defined per subclass. Put differently, ...
cegredev's user avatar
  • 111
0 votes
2 answers
183 views

Should we put behaviors (method) in constant class in Java?

Should we put behaviors (method) in constant class in Java? If not then why? Which clean code practice/principle I am breaking while doing that? public class TagConstants { public static final ...
Pulkit Gupta's user avatar
0 votes
3 answers
2k views

DDD - storing and retrieving entities of an aggregate from the outside

In my doctor's appointment booking system, I identified the following entities: Doctor Patient Appointment I also identified an aggregate, which is Doctor (aggregate root) and Appointment. It's an ...
lamb_bd85's user avatar

1
55 56
57
58 59
68