Stack Exchange Network

Stack Exchange network consists of 174 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

4
votes
1answer
97 views

Repository that performs API calls internally - DDD

Please note: although my question relates to DDD, I am also interested in this from an architectural and OO design perspective. This question may also be a simple case of CQRS and/or interface ...
2
votes
1answer
136 views

OOP Encapsulation Philosophy

Is it fair to say that it is good practice to default everything to private up when defining a class? For example, for my public interface I would set my class something like this: class foo { ...
1
vote
1answer
93 views

What to do if some parameters become constants inside a particular class

I'm sure there's some programming paradigm to cover this case, but I can't find the correct wording for it, and therefore my Google-fu is worthless. I have a class called SimpleWorld that has methods,...
0
votes
1answer
32 views

If I need connection to get data, then display the data at controller A, should I “Connect->To controller A”, or “To controller A->Connect”?

For example, suppose I have a shopping app, which has a user info page to show user info: class UserInfoController{ toPurchaseRecord(){ } } and a purchase record page to show purchase record,...
0
votes
2answers
112 views

Design Pattern to extract arbitrary field from arbitrary file format

Lets say I have multiple file types: .json, .csv ... etc These file types come in different formats: Second json structure Extra column added to csv etc. I need to extract fields from these files;...
12
votes
4answers
593 views

struct with nonsensical default value

In my system I frequently operate with airport codes ("YYZ", "LAX", "SFO", etc.), they are always in the exact same format (3 letter, represented as uppercase). The system typically deals with 25-50 ...
2
votes
2answers
118 views

Strategy/domain object responsibilities

Assume we are in the world of car rental application :) Let's say that I have 3 types of cars with 2 categories of price: Car type Price category ------------------------------ Sport ...
2
votes
3answers
506 views

What is the name of this pattern (if any)?

There's a sort of pattern that I've sort of stumbled myself into "discovering" that seems extremely useful, but I've never seen it described before. It's sort of a way of achieving inheritance through ...
6
votes
4answers
261 views

Passing around large value objects vs converting to smaller value objects

Let's say I have a project that needs to do the following: Multiple calls to read from the database where each call is a different query and returns back a value object (just has getters/setters). ...
-2
votes
1answer
58 views

Using a class as an attribute in another class or just one value?

I have a PHP script which has a group class and a component class. Each group consists of several components. My group has attributes groupName, groupId and componentList. My component has a ...
2
votes
5answers
156 views

Is a point drawn on a canvas considered an entity in domain driven design?

I'm reading on DDD and came across this excerpt: Let’s consider a drawing application. The user is presented a canvas and he can draw any points and lines of any thickness, style and color. It is ...
1
vote
1answer
47 views

Creating objects from a class/classes with different fixed values which can be easily expandable by a user

I am creating a program, and I would like to know the best practice for creating a class which defines different fuel types For instance, I have the following class that I have written in python: ...
5
votes
3answers
139 views

Process an undefined number of class states

Let's say I have an entity Foo. That entity could have a 5 states: A, B, C, D, E(in real application number of statuses can be larger). I store that entity in a database and map it to class. Every day ...
8
votes
2answers
364 views

Difficulty making this class open-closed

Here is my problem: I want to read input from different HID devices such as a gamepad, racing well, joystick, etc. Pretty much any game controller. The issue is that they all have different inputs. ...
2
votes
1answer
80 views

Configurable sorting strategies

I need to be able to sort an object by multiple conditions, and these sorts need to be configurable from the application.properties file (as in it should be possible to specify in the file the sorts ...
1
vote
3answers
100 views

POLA, Constructor and Getters

As a followup to this question and one I asked a while ago, suppose if I had an Author class structured like this: class Book { private String title; private Set<Author> authorsSet; ...
1
vote
3answers
369 views

Is calling .sort() in the constructor a violation of the guideline that a constructor shouldn't do work?

Suppose I have the following List to hold a list of fruits. Example: def fruits = ["Apple", "Orange", "Grapes"] def fruitsBowl = ["Apple", "Grapes", "Orange"] // Will print false println(fruits....
1
vote
2answers
66 views

Factories and event binding

Factories are used to create objects. I was wondering if it's against the purpose of a factory, if I would bind couple of objects together in the factory. Let me illustrate this with an example. Let'...
5
votes
3answers
119 views

How to untangle a data class where annotations from different frameworks mix?

The framework mix problem I'm using two frameworks -- PingIdentity's SCIM 2 SDK and Spring LDAP -- to deserialise a SCIM resource (i.e. JSON) to a Java object then write it to an LDAP directory, and ...
0
votes
2answers
134 views

Require_once in class files

I have a big system of classes and objects which rely on each other in order to function. Should I put all of the require_once() calls for dependencies at the top of each class file? ie: <?php ...
-1
votes
1answer
38 views

How to model parent/child composite when the child is related to another class

I don't know which is the correct way to model this requirement in OOD: A device has many properties, each property has exactly one device parent. There are a set of procedures and a specific ...
0
votes
1answer
66 views

Would you implement an interface to connect to a database?

I found in a book (Learning PHP Design Patterns, Chapter 2, page 25) a text explaining the importance of interfaces in OOP design. The author ended up by giving this example: <?php interface ...
3
votes
1answer
68 views

Auto-Initializable Objects Pattern

I'm working on a system where we consistently apply "patterns" or approaches such as Dependency Injection. I'd rather not expose the current underlying technology as not to get biased solutions, ...
1
vote
1answer
210 views

Architecture / Design Pattern for Login Signup

I have a multi-seller ecommerce platform, derived out of Opencart 2.3. We changed quite a bit of the core code of the Opencart to add our own customizations, including features such as Seller ...
2
votes
4answers
535 views

What do OOP languages gain from having constructors that always return an object?

In what seems like a deliberate design decision, C++ does not have a null value for objects and references. This makes using objects and references very elegant since we don't have to perform null ...
4
votes
1answer
119 views

Best practices when designing a workflow engine using timers?

I'm working in a OOP language called Fantom, similar to Java, to create a workflow engine. My code sends emails to users, and it awaits for users to click a button within the email. In my current ...
5
votes
4answers
1k views

C# has no friend class - what are better options

I return to this question every couple of years, so now i decided to solve it once and for all, by asking here. So, the sequence: I'm writing a simple application that parses Json file (...
1
vote
2answers
228 views

If a instance method is used in one place only, should I move that method to that place?

For example, suppose I have a ZipCode class: public class ZipCode{ public value String value; public boolean validateFormat(){ ... } public otherMethod1(){ ... }...
2
votes
1answer
71 views

How do I refactor a graph service to where I can encapsulate if/then/else statements?

I have a graph service where I use if/then/else statements. class GraphService { function getGraphData(array $products) { foreach ($products as $products) { $...
3
votes
2answers
191 views

Object Oriented vs. Procedural Processes in Embeded System

I'm currently developing a controller for an industrial application which takes data inputs from various sensors and interfaces (ethernet, serial, etc.), does some minimal processing, and adjusts ...
0
votes
4answers
643 views

Avoiding vtable pointers in objects in C++

In my previous question, it was highlight that implementations of C++ such as GCC must store a vtable pointer in every copy of a class for each parent class which has a virtual function. So a class ...
3
votes
2answers
268 views

Does composition increase or decrease the coupling

We know that composition is a synonym of loose coupling. From here I read coupling becomes stronger between the classes A and B when: A has an attribute that refers to (is of type) B. To ...
2
votes
2answers
93 views

Should methods be part of your persisted entities?

We are coding a small game and have a Player class. This Player class has certain properties which you would persist in a database like Id, Level, Health. We would like a Player to be able to kill ...
0
votes
1answer
188 views

Should services be used in a ViewModel

So I have a service which is injected in my controller via dependency injection. I can either use it in the controller multiple times to convert a value when assigning to a particular property in a ...
0
votes
3answers
279 views

Is there a programming language with objects and generics, but without inheritance?

The GO programming language has objects but no inheritance. It also has generics for the built-in types Array and Map. Is there a programming language with objects but no inheritance and with generics ...
1
vote
2answers
326 views

DDD Best practices

I'm developing some test web-project for my self to learn DDD and good architectural practice at all. So application, basically, is a simple photo manager. I'm developing 3-tier architecture and for ...
3
votes
1answer
312 views

NodeJS (ES6): Design Pattern with bind usage

The question is related to the resolution of the this operator in Javascript classes. NodeJS now supports ES6 classes. The problem faced during this is that when a new instance of the class is created ...
-1
votes
3answers
180 views

Should a simple factory method include the “new” operation?

For example, suppose I have a class to create a button with specific styles common to my app, I can have either Return a new modified object: public class ButtonFactory { public static Button ...
3
votes
5answers
232 views

Does deciding about Liskov sub.princple compliance require a contract?

I have read two opinions on the subject. Let's assume the following simple code: class Enemy { public virtual void CheckHealth() { if (Life <= 0) Dispose(); } } ...
0
votes
2answers
165 views

Get data from the byte array

I have a byte array and a value defining the type of the data stored in it (string, int, ...). What is the best way to get this data? I have two options in my mind: Call a method which gives the type ...
0
votes
2answers
82 views

Base class with common properties

I have multiple classes that have the same properties to be exposed. Is it normal to create a base class, which will expose those properties, to be used with descendent classes? By properties I ...
0
votes
4answers
137 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* ...
2
votes
4answers
151 views

Object Oriented Game Programming Board Class decision

I am writing an object oriented game for fun where players from two teams fight. I need to implement move function for players on a maze. Maze sohuld have location information with some features like ...
17
votes
9answers
2k views

How is polymorphism used in the real world? [closed]

I am trying to understand how Polymorphism is used in a real life project, but I can only find the classical example (or something similar to it) of having an Animal parent class with a methodspeak(), ...
2
votes
2answers
131 views

Pattern Matching in OO code

I have a situation where I need to model objects that don't share common attributes but represent same logical entity. Now, based on their type they will have different attributes (properties). To ...
1
vote
6answers
334 views

Is it okay to have a parent class that doesn't represent an entity and doesn't have an “Is-A” relationship with its child classes?

I want to have an array that can hold elements of many classes data types, and each of these classes have a method called printInfo(). The way I can do that is by having a parent class called ...
4
votes
5answers
526 views

What is the “killer feature” of OOP? [closed]

I don't have much experience working with OOP, so I'm trying to understand what is the feature (or features) that would give you a great motive not to write some program in a procedural language, but ...
2
votes
4answers
278 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
273 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
443 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']) &...