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)

5
votes
5answers
1k views

When should I extend a Java core class

My current understanding of Inheritance implementation is that one should only extend a class if an IS-A relation is present. If the parent class can further have more specific child types with ...
-1
votes
2answers
23 views

Cache repository violating the SRP

interface IRepository { Data getData(); } class BaseRepository implements IRepository { public Data getData() { ... } } class CacheRepository implements IRepository { private final ...
4
votes
1answer
151 views

Refactoring of a client API for avoid duplicated code and unclear passage of parameters

I need to develop an API, the functions of the API are requests that call the service exposed by a server. Initially the API worked like this: class Server: def firstRequest(self, arg1, arg2): ...
2
votes
1answer
590 views

Emulation of MMU accessing the contents of the registers

I'm having a play around with emulating a simple old CPU. I've set the structure up, so far anyway, as follows: The device is the main and creates an instance of the CPU. The CPU then creates ...
1
vote
2answers
272 views

Multiple instance of the same class?

I have a class named "Category" to handle all the operations and data about my categories. Now, my class is created however I need to find a way to build an object for each of the categories in my ...
-3
votes
0answers
46 views

Type safe substituion for parameter passing [on hold]

What are some examples of type safe substitution for parameter passing as well as for return types in subtyping introduced through subclassing. Does the Liksov Substitution Principle apply to them?
7
votes
2answers
140 views

Am I using Zend Form library correctly? (I am effectively duplicating work in Controller and in View)

Brief Summary This question is asking for guidance on how to deal with Zend Form library that allows me to specify how to construct each form element (Controller side) and how to render each element ...
2
votes
1answer
142 views

Child class accessing its parent's method from Ancestor method

I find myself right now banging my head with the following issue (in PHP): I have an abstract base class, which has a non-abstract method, inherited and unchanged all over the inheritance chain ...
-6
votes
0answers
59 views

Help me in this java programs [on hold]

Write a program: Must start if user says hello Has to repeat until the user says bye Ask user to enter his or her name, let him or her know if the entered name contains space or dot. Each time print ...
1
vote
1answer
39 views

How to use fields from an object after an exception is thrown and the object can't be fully created

The issue that I have is that I need information from an object that a method returns when it throws an exception. It is a little hard to describe so I have this java pseudo code example. I have a ...
0
votes
0answers
42 views

Good examples for use of design patterns in Unity [on hold]

My students have learned OOP as well as the strategy design pattern during the first semester (Processing/Java), which lead to understanding Unity's component based architecture (similarity of ...
6
votes
1answer
426 views

How to make clear that a method can be overridden?

I have a library that I use in several applications. It has a method that returns a URL: class UrlBuilder { public function url($config) { $config = do_some_checks($config); return ...
0
votes
1answer
93 views

How to store state data when the data is related to another entity?

In order to increase the parallel-ability of my objects, I try to make them read-only and include only data that naturally belong to the entity. I have class Object { ... }; class Processor { ...
1
vote
0answers
14 views

How to Make Reusable Classes/Package in Laravel for Billing which uses PaymentExpress?

I am working on a Laravel Project where we are Payment Express. What currently we are doing is that we have Payment Express Class with static function (Not a single property) like given below: Class ...
5
votes
3answers
211 views

Is it ever appropriate to use subtyping for a has-a relationship?

One of the basic precepts of object oriented programming is that subtyping represents the "is-a" relationship. That is, the child is always a specific form of the parent. A common example is that a ...
4
votes
3answers
138 views

Who is responsible for checking object properties such as Visible/Enabled?

Say we have a user interface with Forms, Buttons and such. Each item has some properties (such as Visible, Enabled, etc.). Who should check on these properties and decide whenever to render the item ...
1
vote
2answers
129 views

Expressing interface inheritance in natural language [duplicate]

In object-oriented programming, when you extend a class you establish an is-a relationship between a new subtype and its parent(s), i.e. B is an A (aka code inheritance). When you compose a class with ...
1
vote
1answer
34 views

In a .NET Windows Forms app with a custom MVC, should a custom UserControl (view) implement any non-animating logic on its own?

This is strongly linked to these two questions: http://stackoverflow.com/q/15800945/279112 Should Controller know about View & Model? or vice versa? as well as this one: ...
169
votes
13answers
49k views

Should we avoid object creation in Java?

I was told by a colleague that in Java object creation is the most expensive operation you could perform. So I can only conclude to create as few objects as possible. This seems somewhat to defeat ...
2
votes
1answer
141 views

Checking preconditions the proper way

I have a class with around 1300 lines and it has many CRUD-like methods that need parameters to be checked, for some of them it's more than just a few rules. For clarity purposes, I am going to use ...
3
votes
1answer
205 views

How to pass data to OOP objects?

I'm new to this whole thing, so please tell me if I'm doing this wrong of if there's a better spot for my question. I'm making a game with basic systems for projectiles, npcs and items. This game ...
1
vote
0answers
31 views

Why Does JavaFX's GridPane Attach Properties of the Layout to the Components?

I am currently learning JavaFX and I came across a very strange API for laying out GUI components. It is perhaps best explained by it's javadoc: To use the GridPane, an application needs to set ...
9
votes
3answers
249 views

OOP design problem. Two kinds of empty Optional

I'm writing a quite simple application that deals with hotel rooms reservation. I've got a problem at one stage. I'm processing a queue of orders. For every order one of the receptionists should ...
3
votes
5answers
187 views

What is the correct OOP relation between complex and real numbers?

On one hand class complex { double real; double imaginary; } it is composition on the other hand class complex : double { double imaginary; } it is inheritance Which one is ...
16
votes
3answers
2k views

Is there a specific name for the “Square inherits from Rectangle” paradox?

A certain failure of OOP is shown with a class Square inheriting from Rectangle, where logically Square is a specialization of Rectangle and should therefore inherit from it, but everything falls ...
1
vote
2answers
63 views

Implementing an event scheduler for animations

The basic idea is to have some animated widgets that sit in a container, quite similar to Qt (the only actual difference is that my widgets are animated). The animation is in some cases dependent on ...
-1
votes
1answer
38 views

algorithm to convert technical specification into object model [closed]

I have detailed specification of what should my program take as input, and give as output. How to convert this specification into classes/methods/properties? I used such algorithm: Take ...
1
vote
1answer
46 views

Redesigning a builder to make it reusable

Let's say I have a builder class (which by the way is not techinically a builder, but it's not a factory either) to generate different rules for a game: public class RuleBuilder { private Game ...
4
votes
4answers
961 views

Is this a Single Responsibility Principle violation?

I'm designing an OO graph library and at the moment I'm trying to figure out the design for a GraphEdge class. I've added setters and getters for it's nodes, direction and weight. This seemes ...
13
votes
4answers
1k views

How specific should the Single Responsibility pattern be for classes?

For example, suppose you have a console game program, which has all kinds of input/output methods to and from the console. Would it be smart to keep them all in a single inputOutput class or break ...
-1
votes
2answers
95 views

Do you say “this” on protected members? [closed]

Background I have never had a formal class in OOP/OOD although I understand how the protected members work. Being accessible by any instance/derived class, they are thereby less private (more ...
17
votes
7answers
1k views

Patterns for propagating changes up an object model..?

Here's a common scenario that's always frustrating for me to deal with. I have an object model with a parent object. The parent contains some child objects. Something like this. public class Zoo { ...
2
votes
2answers
84 views

How to handle when only certain derived classes need to be disposed?

I am trying to build a framework of objects where the main actors can be interchanged freely. At the moment I've done this by creating an abstract base class that all of my actors can be derived from. ...
1
vote
1answer
179 views

OOP: how to keep some state for a brief moment?

My job and my personal interests often have me writing parsing code, that is, code that converts from an input string written in a given formal language to a tree of model objects. I come from a C ...
0
votes
3answers
184 views

DDD Request Validation Handling

I stuck somewhere that I can't find a solution! There are plenty of validation questions here, but as far as I see, most of them were asking about entity validation. But what about request validation? ...
0
votes
1answer
138 views

What would be the merits/disadvantages of an OOP language that forced the generator pattern?

In OOP languages, programs can define static methods that can generate objects with different parameters (including subclassed or pre-generated objects), but they are not as commonly used because we ...
1
vote
4answers
921 views

How do you make a service stateless?

When doing Domain Driven Design it is advised that services should be stateless. There are several kinds of services when doing DDD: Application services. Domain services. Infrastructure services. ...
4
votes
4answers
290 views

Should an object be able to represent itself across components?

I'm working on a networked game. I have tried to design the various components (client, server, engine) to only about things within their domain. For example, the server should only be concerned with ...
0
votes
1answer
82 views

Question(s) about PHP PDO connections

Let's say I have a Db class [ db.php ] : <?php class Db { // class properties private $db_driver = ''; // dsn credentials private $db_dhost = ''; private ...
0
votes
1answer
71 views

Passing a Serial Port Instance

Background I am thinking about designing a (GoF/behavioral) command-pattern interface. I may decide to call this thing ICommand. I am thinking that I would have some sort of a queue containing a ...
1
vote
1answer
124 views

Returning functions within Javascript objects

After coming across Douglas Crockford's views on class-free OOP, and doing away with new and this in Javascript I tried defining an object with its own variable and function, and returning it in a ...
5
votes
3answers
106 views

Understanding Multiple Dispatch

I've been reading around trying to understand multiple dispatching, and why it's so special. On Wikipedia I came across this simple example: (defmethod collide-with ((x asteroid) (y asteroid)) ...
2
votes
2answers
130 views

Do the implementations of the Node interface in Web API violate Liskov Substitution Principle?

MDN article on Node interface states that interfaces [that inherit from Node interface] may return null in particular cases where the methods and properties are not relevant. They may throw an ...
24
votes
7answers
3k views

How to return warnings alongside result of calculation to caller of a Java method? [duplicate]

I have a class, lets call it Calculator, with a method like this: public double[] performCalculation(double[] someInData) This method can generate a number of non fatal warnings (represented as an ...
25
votes
11answers
2k views

Does Refactoring towards Looser Coupling, Smaller Functions, and Separate Classes affect System Performance? (and Should I Care)

Lest you be confused by what's to follow, here is the driving idea behind the question: I always intended the question to be what it is. I may not have articulated it well originally. But intent ...
13
votes
5answers
3k views

When to use interfaces (unit testing, IoC?)

I suspect I've made a schoolboy error here, and am looking for clarification. A lot of the classes in my solution (C#) - dare I say the majority - I've ended up writing a corresponding interface for. ...
0
votes
5answers
500 views

Liskov Substitution and SRP Principle violation - how best to structure this scenario?

While learning SRP and LSP, I'm trying to improve the design of my code to comply best with both of these principles. I have an employee class that has a calculatePay method on it. Firstly, I believe ...
3
votes
2answers
502 views

Does this Decorator implementation violate the Liskov Substitution Principle?

Please consider the following implementation of the Decorator design pattern: WordBank objects store strings and return them to the client through the method getWords(). The decorator class, ...
2
votes
2answers
101 views

Design of object alias

Suppose you develop an interpreter or file system. There are objects, like variables, procedures and files in some environment. They have a name and content (variable has current value, procedure has ...
2
votes
1answer
1k views

Liskov principle: violation by type-hinting

According to the Liskov principle, a construction like the one below is invalid, as it strengthens a pre-condition. I know the example is pointless/nonsense, but when I last asked a question like ...