A methodology that enables a system to be modeled as a set of objects that can be controlled and manipulated in a modular manner

learn more… | top users | synonyms (3)

3
votes
2answers
324 views

What alternatives to a singleton are there for a class which only can have one instance?

I need to represent an abstraction over various parts of the hardware for a game. I'm trying to decouple the code that does things like manage the logic of the game from the code that is API/platform ...
3
votes
3answers
187 views

Do I need a parent class if I'm using an interface?

I'm starting work a new personal project to send out emails using different email services (like mailchimp, for example). I just started coding and I have a base class called Email: public class ...
0
votes
1answer
80 views

Design patter for a dynamic filter builder

Say that I have an abstract base class Shape and its derived classes Triangle, Square, etc. Currently I have the following (simplified) structure to fetch a list of Shapes and filter them (mostly ...
3
votes
3answers
108 views

Which pattern can I use for doing computations involving similar yet different object subtypes?

How do I design code that has two qualities: uses similar but different subtypes of an object uses similar but different types of computation on the above objects Example I am refactoring this ...
2
votes
1answer
134 views

What is internal state and is there a difference between state and internal state

Ok, this question has been asked before, but it's still not clear to me. What exactly is internal state? So far state is clear to me: Functions contain behavior, variables have state, values don't. ...
2
votes
2answers
151 views

Passing fields (instance variables) by arguments (parameters) inside an object - does it make sense? [duplicate]

I believe this is language agnostic question - if it's not then please correct me. Let's say I have a class (code snippet is a kind of 'pseudo code') class Car: private steering_wheel private ...
1
vote
1answer
164 views

Java code design for a Geocoder Webservice client

Please bear with me, if this type of question has been asked before. I am having a dilemma with object design and seeking experts' help here to come up with the correct/better design for a webservice ...
12
votes
4answers
901 views

How does having too many instance variables lead to duplicate code?

According to Refactoring to Patterns: When a class is trying to do too much, it often shows up as too many instance variables. When a class has too many instance variables, duplicated code ...
0
votes
1answer
81 views

Object oriented programming - subobject vs globals (use case) [closed]

I am developing a nethack-like game, and I would like an advice how to approach the design part. For now I got class like Location, Npc, Item etc. But I've got a problem how to easily access parts of ...
4
votes
3answers
272 views

Composition over inheritance but

I'm trying to teach myself software engineering and coming up against some conflicting information which is confusing me. I've been learning OOP and what abstract classes / Interfaces are and how to ...
0
votes
1answer
37 views

Confusion over organization of services

I have the following services: UserServices This has various methods: fetch_by_id(), create() etc. SessionServices Session handling: create(), destroy(), various getters. AnswerServices An answer ...
1
vote
4answers
93 views

How to design class model for specific products, some of which may contain groups of specific product models

Class Design Question I am trying to figure out a good way to design my class system. I have a class Product to compute various product specifications. I have two product model groups, each ...
5
votes
2answers
179 views

Object Oriented Late Binding

In the Alan Kays Definition Of Object Oriented there is this definition that partially I don't understand: OOP to me means only messaging, local retention and protection and hiding of ...
1
vote
0answers
121 views

Where to store formulas and formula “constants”?

I want to implement a database driven payroll system using CSharp. I already did it once, but the implementation sucks so I want to do it again and do it right. My first thought is to create a static ...
1
vote
1answer
71 views

Object oriented design - Designing business rules

I have trouble designing classes that reflect different business behaviors/rules. An example to explain my case: - a tour has a departure - a departure may be a guaranteed departure if a departure is ...
3
votes
1answer
197 views

Why throw a 'must implement this function' exception rather than making the function abstract?

In the Android support libraries here the destroyItem and instantiateItem functions throw an exception if they aren't overriden: 175 throw new UnsupportedOperationException( 176 ...
2
votes
1answer
138 views

For what reasons would you use a separate class extension for each delegate in Swift?

I was working through a Ray Wenderlich tutorial and noticed that the author uses class extensions to hold delegate callbacks rather than having them be handled in the class itself i.e.: delegate ...
0
votes
1answer
68 views

Patterns for migration to multi-tenant application [duplicate]

I have a complex web application that manages stores and their customers. The application follows a basic MVC architecture and I should migrate it to a multi-tenant application: - I should go from ...
1
vote
0answers
73 views

Lazy loading collection data through granular subscriptions and OOP (Meteor.js)

I am transforming my Meteor collection to a class I've created: People = new Mongo.Collection('people', { transform: function(doc) { return new Person(doc); } }); Person has a bunch of ...
6
votes
3answers
210 views

What data type should Gateway return in Repository Pattern to eliminate refactoring when switching persistence mechanisms?

Following this description of the Repository Pattern, we have three main concerns that need their own classes: The "Repository," which takes and returns Domain Models. The "Gateway," which takes ...
1
vote
1answer
127 views

Child classes only change some “options” - what's the best approach?

I'm currently implementing functionality in Symfony (PHP - not that it should make any difference which language I'm using) where I have about four controllers that do almost exactly the same thing. ...
1
vote
1answer
59 views

OO Design: Reading/Writing object with multiple formats

I have a class Song, which has the following public methods: String getSong(); void setSong(String); int getId(); void setId(int); Now I have two different ways I might want to store these songs in ...
0
votes
1answer
67 views

How to split a class that is an implementation of interface?

Let's say there is class called AccountingService. Using this class I fetch all kinds of ecommerce records like products, customers, etc. The fetching happens inside a controller action. Once fetched, ...
0
votes
1answer
81 views

Should I document expected call-sequences when call-order matters?

In dynamically and weakly-typed languages*, I often find myself with structures like the following pseudocode: class Stateful: # [ various datamembers / attributes / properties / fields / etc. ] ...
1
vote
3answers
147 views

Should I create a class for functions that uses of the database?

I have a PHP application which is pretty simple: It allows the user to create, edit and read a post. Basic stuff. I have a Database class which handles the connection and the queries execution. The ...
0
votes
0answers
206 views

Structured JavaScript Codes

A while ago I started working on a web application which has a lot of JavaScript code due to having a lot of client-side logic. Before starting, I had had a quick look at a couple of JavaScript ...
2
votes
1answer
182 views

OOP - Should I set the database connection as `public` for other classes to use it, although it might be unsafe?

I have a basic Database class, and it has a mysqli property (an object itself) which contains the connection information. Other classes uses this class to read and manipulate the database. There are ...
1
vote
2answers
398 views

Class design for writing multiple versions of multiple files

I am writing a web service in Java which reads some information from a DB and generates multiple JSON files which are written to S3. For each type of file, I have a POJO which is serialized to JSON ...
3
votes
5answers
954 views

When are enums NOT a code smell?

Dilemma I've been reading a lot of best practice books about object oriented practices, and almost every book I've read had a part where they say that enums are a code smell. I think they've missed ...
1
vote
1answer
142 views

Data structures for designing an online book reader

I want to design an online book reader system as a programming exercise. I wrote down the following requirements: Searching a book by title. Bookmarking a book. Mark a book as favorite. Give rating. ...
4
votes
3answers
361 views

Name of this pattern to wrap functionality

I have a system that allows certain functionality to be implemented different ways, but requires that the functionality of each implementing class be wrapped in another layer. For example, each ...
0
votes
1answer
74 views

When designing input interfaces for a library, when to use data class rather than data interface?

Let's say library A, B and C are all custom math libraries. They may or may not use the same data types. The libraries have methods that accept data type inputs like ProcessAsync(DataTypeA) or ...
5
votes
2answers
169 views

Do I violate the Single Responsibility Principle with my multi-purpose AST Class?

I am writing a compiler, for which I devised a rather classic architecture: it's composed of sequential passes piped together, starting with a lexer and a parser, continuing with a macro processor, ...
2
votes
1answer
105 views

Pattern for interface between sequence executing object(s) and sequence configuration objects

My motivating case is hardware test automation. We have several different testers (benches of lab equipment that connect to the "device under test" (DUT)), and we write test configuration files which ...
0
votes
1answer
149 views

Object Communication Design

Multiple top-level systems that communicate with each other via messages(events/commands). The Main class of the program wraps around all the systems and has a message dispacher component wich ...
0
votes
2answers
142 views

Meaning of using getters and setters and Uses of parameterized Constructor. [duplicate]

I am using getters and setters to for the purpose of encapsulation. public class Student { private String studentID; private String studentName; private String address; public ...
2
votes
2answers
97 views

How to store one-to-many graph? Passing root or passing root and children seperately?

Suppose in the application, there is a type Teacher and a type Students. A Teacher may have a list of Students. So in design, class Teacher has a field of type Collection of Students (aka List). ...
0
votes
2answers
88 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 ...
1
vote
3answers
121 views

Classes with one public function replaced with a constructor

I have a number of classes with a single public method. Looking at this answer, I tend to agree with what is stated. The OP lists some examples, which I interpret to be used like (new ...
2
votes
1answer
51 views

Instance methods that modify multiple objects

I'm currently in the process of rewriting an older library for managing documents. I'm having difficulties to specify an interface for the management of links between those documents. Previously they ...
2
votes
2answers
305 views

Python OO problem

I started learning Python yesterday and I ran into a problem. I like to hear some thoughts on it. As an exercise, I decided to build a chatserver. As part of the exercise, I wanted to write some ...
2
votes
1answer
99 views

Does implicit and explicit cast operator overloading violate the D in SOLID principles of OO?

I'm looking at different patterns and techniques for implementing logic to convert object from one class to another, and the most elegant seems to be explicit cast operator overloading (in C#). ...
4
votes
3answers
234 views

What is the best design principle to add behavior in future to your API? [closed]

I'm designing an API. And, this API will be used by client. Currently I've two behaviors in a class definition. To illustrate the scenario, sample implementation looks like the following- public ...
6
votes
3answers
257 views

Is mutually referencing classes a consequence of bad design? [closed]

I am currently working on a small game I did in about ten days. Since I am programming for myself, I am being lazy and going to the easiest solution with (too) little concern about bad code quality. ...
1
vote
2answers
151 views

Performance concern in object oriented languages [duplicate]

I recently moved into web development using ASP.NET MVC. The language I use is C#. Having considerable experience in C makes me look for optimized coding standards (memory, efficient data structures ...
4
votes
2answers
130 views

Does returning pointer to composed objects violate encapsulation

When I want to create an object which aggregates other objects, I find myself wanting to give access to the internal objects instead of revealing the interface to the internal objects with passthrough ...
1
vote
1answer
59 views

Access container object from within an item

Generally I have 3 classes, a container that holds an array of items and a special object that is another property of the container class. What I need to do is access the special object from an item ...
19
votes
5answers
4k views

What are the benefits of dependency injection in cases where almost everyone needs access to a common data structure?

There are plenty of reasons why globals are evil in OOP. If the number or size of the objects needing sharing is too large to be efficiently passed around in function parameters, usually everyone ...
2
votes
4answers
243 views

Why shouldn't pure functions always be static and public? [duplicate]

What are the reasons, technical or otherwise, that pure functions (functions which do not rely on external state and have no side effects) should not always be public and static? When a static and ...
2
votes
2answers
319 views

How is encapsulation broken by getters/setters, even when using MVC model [duplicate]

I was thinking about encapsulation in Java and then I thought how getters/setters break encapsulation. After I went through this , I saw many recommendations like to avoid getters/setters on fields ...