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)

0
votes
1answer
69 views

Is it always better to use __construct() in CodeIgniter's Models and Views, even if it's not needed? [closed]

Sometimes we have Models and Controllers where the function __construct() just doesn't do anything, but is sitting on the top of all the methods in CodeIgniter's models and controllers. A lot of ...
3
votes
1answer
179 views

Why is abstract Decorator class needed in this example?

Why do we need ShapeDecorator in this design? Why can't we just have RedShapeDecorator implement Shape directly and inherit from Shape?
0
votes
0answers
41 views

Why doesnt the Factory Pattern violate OCP? [duplicate]

Why does this ShapeFactory use conditional statements to determine what object to instantiate. Dont we have to modify ShapeFactory if we want to add other classes in the future? Why doesnt this ...
3
votes
3answers
366 views

Generics vs common interface?

I don't remember when I wrote generic class last time. Every time I think I need it after some thinking I make a conclusion I don't. The second answer to this question made me to ask for ...
2
votes
2answers
137 views

Private variables and the old FORTRAN common blocks [closed]

This is a question that perplexes me about object oriented programming. In some OOP languages (e.g. C++) a member function can access private variables of the class without restriction. That means ...
3
votes
2answers
166 views

How to handle Data Fetching for Circular Object References in OOP Domain Models

I'm trying to put together some basic models in OOP (C#), and apparently I've got the wrong idea. If I have a Workman's Comp case, it is applied to a Patient. It also has one or more PatientVisits ...
6
votes
5answers
436 views

Object Oriented Design Question

I have long experience in procedural world and been programming/maintaining OO code in various languages too. Now getting into OO design and feeling the pains of identifying objects from scratch. Been ...
5
votes
3answers
455 views

Why do you need “self.” in Python to refer to instance variables?

I have been programming into a number of languages like Java, Ruby, Haskell and Python. I have to switch between many languages per day due to different projects I work on. Now, the issue is I often ...
7
votes
5answers
442 views

Refactoring three very similar classes using inheritance?

I'm currently working on refactoring the code-base for one of our services. I'm been going through reviewing everything, and I feel it's a bit scattered, and could probably adhere to OOP principles ...
0
votes
2answers
189 views

Does Python have any features which can be used for encapsulating private data?

Usually in OOP world we are told that modularity is a good practice and keeping loose coupling between module is a great thing. Encapsulation helps us achieve this loose coupling. In Java ...
2
votes
1answer
128 views

Using a switch vs multiple classes and a hashmap

So I have a file to process that contains a command on each line. Currently it's implemented like this(this is a refactoring assignment): hashmap.get(commandStr).sendCommand(); The objects(4) ...
3
votes
2answers
325 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
190 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
84 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
109 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
140 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
154 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
165 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
907 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
277 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
94 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
180 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
124 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
72 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 ...
3
votes
1answer
150 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
78 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
212 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 ...
0
votes
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
60 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
69 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
148 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
213 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
188 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
404 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
980 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
144 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
78 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
170 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
106 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
150 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
89 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 ...