Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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

2
votes
4answers
281 views

Is there an object-oriented language that doesn't allow you to have private member variables? [closed]

I know that JavaScript doesn't explicitly allow you to have a member variable of an object as private, but you can do that implicitly by using closures. But is there an object-oriented language that ...
0
votes
6answers
421 views

How to restrict method's parameter to the class, where the method is overridden

I have quite simple class hierarchy: public class Base { //... public virtual void AssignFrom(Base baseObj) { //DoSomeStuff } } public class DerivedA : Base { //... ...
0
votes
1answer
624 views

PHP MVC controllers using ajax

I'm learning to use the MVC pattern to design my PHP's software. I always use ajax to send requests to my controllers so often I've a code structure like this: <?php if(isset($_POST['action']) &...
45
votes
8answers
12k views

Before OOP, were data structure members left public?

When a data structure (for example, a queue) is implemented using an OOP language, some members of the data structure need to be private (for example, the number of items in the queue). A queue can ...
2
votes
0answers
255 views

Design a Windows Service with self-hosted ASP.NET Core Web Services and UPD port listeners

I'm designing a software platform in automation that is responsible of many different tasks like: Core functions Driver interface for machines UDP listener for machine messages from PLC UDP listener ...
0
votes
1answer
73 views

Should I print to the page from a javascript object, or only render from PHP?

I have a complex app on the Javascript/PHP/SQL stack which manages different domain objects. The Javascript layer contains classes which manage the data on the client side. I am currently baking a ...
0
votes
1answer
59 views

Adapting third party conversions

I have a couple of pieces of functionality that are similar but not quite the same. They both involve converting a type that I own to other types that are owned by a third party library, so out of my ...
0
votes
1answer
81 views

Where should the domain rules be applied on user input?

The application is an API. Users can post data to the API, which is then transformed to a domain object. I am wondering where to apply the domain rules, in the domain object. Let's make it more ...
2
votes
1answer
307 views

Is 'Keep it looks similar to sample code' a valid reason to prefer WET over DRY principle?

For example, for oauth, I may need to copy and paste oauth and oauth callback code like it (assume Client is the framework I use, I don't use real framework like google because I want to simplify the ...
0
votes
1answer
147 views

When doing oop in python where should I add the logger

When doing oop in python where should I add the logger. Should I add it: before the class Rocket(): and give it a file global scope or after the class Rocket():  and give it a class scope. Syntax ...
4
votes
4answers
231 views

C++ Preferred method of dealing with implementation for large templates

Typically when declaring a C++ class, it is best practice to put only the declaration in the header file and put the implementation in a source file. However, it seems that this design model does not ...
2
votes
3answers
165 views

Is there a pattern to describe a class that symbolises an instance of an instance of another class?

I am currently working on a project that generates videos from templates (a template being a collection of JSON files and assets). It seems natural to have a Template class that contains all the info ...
2
votes
0answers
76 views

Creating bindable input handler in C++ spanning two separate modules

I have a wxWidgets application. This is the first, main module. The second module is an openGL engine. It's a model-view-(controller) structure, where application is the view (and the controller), ...
3
votes
2answers
497 views

How is usually named a non-const getter?

Quite often you need to define a getter returning a reference to a member, and a corresponding setter. They usually look somewhat like this : class Foo { Type member; public: const Type& ...
2
votes
0answers
63 views

Memento and releasing resources

Let's suppose we have a class whose state has to be saved and later restored, and we resorted to the Memento pattern for that. What if the state includes resources that have to be explicitly ...
2
votes
2answers
364 views

Is this Aggregation or Composition?

As far as my understanding for composition, the children cannot exist without the parent. But my instructor is suggesting that the following example is an aggregation, I just want another opinion. ...
10
votes
6answers
896 views

Is separating most classes into data field only class and method only classes (if possible) a good or an anti-pattern?

For example, a class usually have class members and methods, eg: public class Cat{ private String name; private int weight; private Image image; public void printInfo(){ ...
-1
votes
1answer
148 views

Does Interface Segregation Principle apply to parameters/request objects?

I have recently seen an example of what I think is a clear violation of ISP, but my colleague argued it is easier to use. This is what happened: We had Options class that had 2 fields sent as a ...
1
vote
5answers
624 views

Designing a card game

I want to expand my personal projects portfolio, so I decided to make a card game. To be more precise, it's called Macau. I've read this answer on StackOverflow and tried to follow the steps from the ...
0
votes
2answers
88 views

Class design : Decide between file and database for storage during runtime [closed]

Based on the demo or license version of my application, I am supposed to either save the data to a file (xml) at a specific location or a relational database. What should be my approach for this case ...
1
vote
2answers
84 views

Designing a graph-like drawing application

I am dealing with a drawing app that allow the user to draw a set of Components (which are like the graph vertices) and they can be wired (like the graph edges) on each other to simulate how their ...
0
votes
1answer
56 views

Privacy in prototypal inheritance

People say that everything in The prototypal inheritance is public But we can achieve privacy using closures in the constructor right? function Cons(id){ this.name='Hermit'; this.check=function(){ ...
3
votes
1answer
172 views

Does adding values to a dictionary in the constructor violate that “a constructor shouldn't do work”?

Some what of a followup to this question. Suppose I have a Player class with a dictionary call attributes that holds the Health and Mana of the player. In this example, I'll use Python, but my ...
-1
votes
1answer
165 views

Design pattern for a sequence of related operations

I have a use case where I need to process a request as follows Authenticate the Request Authorize the Request Validate the message (Reads the database for the existing record and validates it) ...
1
vote
3answers
229 views

Rethinking inheritance when subclass implements interface

Suppose if I have an abstract Weapon class, and the subclass ReloadableWeapon which implements the interface Reloadable. interface Reloadable { void Reload(); } public abstract class Weapon{ @...
1
vote
1answer
91 views

How to define a system class?

My course notes have stated that a system should have a system class which coordinates the behaviour of all other objects in the system and should be one which is instantiated only once. In many ...
1
vote
1answer
106 views

How to design service layer when working with model objects and relationships

I have a simple relationship where top-level items (Recipe) have a one-to-many relationship to children (Ingredient) and each item has a unique identifier (ID). For simple CRUD operations the flow is:...
-1
votes
1answer
157 views

Is it bad practice for a composited instance to reference its parent? If yes, why?

I'm building a Selection class that holds and allows manipulating selected Items on a canvas. The Selection is part of the Document, the top-level app-container if you will. I'd like to be able to ...
2
votes
6answers
764 views

Should I still prefer composition over inheritance if the child classes need BOTH the parent interface AND its class properties?

According to Why should I prefer composition over inheritance?, I should prefer composition over inheritance. But what if I need to access the interface and class member in generic way? For example, I ...
0
votes
2answers
126 views

design discussion, user experience first or correctness first in our case

We are discussing the system configuration module design in our Java medical device software. The system has a voice instruction function used to guide patient during the examination. Different ...
4
votes
2answers
301 views

Clean Architecture: get instance in inner circle of class from outer circle

This might be an easy question for experienced software engineers. I'm currently reading the book Clean Architecture by Uncle Bob, and I'm trying to implement clean architecture in a Java project. ...
1
vote
1answer
97 views

How to fetch data based on id from isolated code cleanest way?

I'm working on client-server application. Client architecture (class hierarchy) looks like this: System (name is of course different, more descriptive) - represents whole system Module A - a class ...
5
votes
2answers
250 views

Using static factory methods to prevent unwanted input

Many years ago, I posted a problem I had with some code and received a well written detailed answer that suggested the use of factory methods. I liked this approach, because I can provide a method ...
0
votes
0answers
50 views

Creating a central repository for repositories with related data?

I am building a website for a fruit company. In my database I have a list of countries, and for each country, a list of distributors that sell my fruit products. The country and distributor are ...
2
votes
5answers
405 views

Interfaces Everywhere? - Best Practices [duplicate]

There is a discussion at work about the correct use of interfaces in OOP. I have been taught, and always worked from the premise, that interfaces precede concretions and all methods should be dealing ...
1
vote
2answers
219 views

Does it violate SRP to reject subclass method parameter

I was having a good read on Eric Lippert's blog about Wizard and Warriors. It suggests the creation of a Rules class, quote: We keep on talking about “rules”, and so apparently the business ...
3
votes
2answers
367 views

In which programming paradigm can't code reuse be (easily) achieved?

In a video about software architecture that I'm watching, it's stated that the main program/subroutine architectural style promotes modularity and function reuse Code reuse is one of the main ...
1
vote
1answer
226 views

Does creating a list in the constructor violate the guideline that a constructor shouldn't do work?

I was reading these pages (1,2,3), but I'm still unsure if this violates the guideline. I have the following data being read from a website: Date: July 13, 2018 Type: Partial Solar Eclipse Location:...
1
vote
1answer
176 views

Is it usual to “re hydrate” DTOs into full objects with relationships when consuming web services?

We are designing a web API to transfer objects obtained from a database to a client application which is a front end GUI. The server side business logic will be implemented (for better or worse) in ...
0
votes
1answer
214 views

Should the aggregate root have a property that it cannot validate [duplicate]

I ran into the situation where I have to decide whether a property belongs to my aggregate or not. My domain logic is the following. A User has a group in his organization ex: IT, SALES, MARKETING. ...
5
votes
2answers
120 views

How to represent relations between multiple objects without obvious aggregate root

Let's say we have three types of objects: Agents Calls CallsQueues They all can be linked with each other (1to1, 1toM, MtoM) or have no links, and these links change over time. Calls wait in ...
3
votes
2answers
113 views

Object design: Class property vs. list of objects

We have an object-oriented database. So, our persistence is truly object oriented. The example is the object person and the attribute VIP. We have to store, if a person is a VIP or not. Usecase: ...
-2
votes
2answers
229 views

Why we are moving towards Mixed Programming Paradigm [closed]

C had Procedural Paradigm, then C++ came with OOPS and success of JAVA make it best suitable Programming Paradigm. Now, Look at recent trends, Kotlin, Swift these languages are not like JAVA these ...
-2
votes
2answers
214 views

Can we say Apple inherits from both Fruit and Seed classes?

Given three classes Apple, Fruit and Seed ; Apple is a kind of Fruit and it has Seed in it. With the knowledge of Apple Class uses directly or indirectly the properties of Fruit and Seed. Can we say ...
-1
votes
1answer
117 views

When to Method and when to Class? [closed]

Following SOLID first principle, the Class should be responsible for only a single part of the functionality provided by the software. The same, I guess, goes with the Methods design principle. They ...
0
votes
2answers
292 views

Method for updating a reference type - return object or use void

What is preferred and why? void PrepMyInstantiatedObject(SomeComplexDTO someComplexDto){ someComplexDto.Name = SomeOtherClassHelper.DerivedName(someComplexDto.Name); someComplexDto.Ids = ...
0
votes
1answer
188 views

Class definitions in static getter methods

[Node.js / CommonJS] I'm creating a single GitHub repo for my tool which has a Core, Control, Server, and Client library. It's unlikely that all of them will be used at the same time. I'd like my ...
1
vote
1answer
172 views

Limitations of using classes as interface

I am an Electrical Engineer now training and working as an embedded software developer, so I have little formal computer science and software design training. I have until a few months ago only worked ...
0
votes
4answers
147 views

Best practice to populate a `container` class

lets say I have several objects Object A,Object B,Object C in different parts of my project. I have defined a Object X that is only used to store some specific values from the objects mentioned above ...
5
votes
5answers
293 views

A problem of decoupling

This is a simplified version of a problem I'm facing in my current project. Let's say we want to display shapes: rectangles, circles, etc. I'll have a Shape class which is subclassed by Rectangle, ...