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)

35
votes
5answers
3k views

When should I extend a Java Swing 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 ...
-4
votes
2answers
54 views

Cache repository violating the SRP [closed]

interface IRepository { Data getData(); } class BaseRepository implements IRepository { public Data getData() { ... } } class CacheRepository implements IRepository { private final ...
1
vote
2answers
301 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 ...
7
votes
2answers
166 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 (...
1
vote
1answer
45 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 ...
6
votes
1answer
443 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 make_url(...
1
vote
0answers
31 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
216 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
141 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
133 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 ...
176
votes
13answers
51k 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 ...
3
votes
1answer
166 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
227 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
45 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
283 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
202 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
votes
1answer
43 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
51 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 ...
5
votes
4answers
970 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
107 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
91 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
182 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
1answer
142 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 ...
4
votes
4answers
296 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
95 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
133 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
115 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 ...
14
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
502 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
522 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
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 ...
13
votes
1answer
1k views

How to verify the Liskov substitution principle in an inheritance hierarchy?

Inspired by this answer: Liskov Substitution Principle requires that Preconditions cannot be strengthened in a subtype. Postconditions cannot be weakened in a subtype. Invariants ...
6
votes
2answers
744 views

Is it good to have an interface plenty of methods which belong to different concepts, just to preserve the Liskov's Principle?

I'm currently studying a course based on Software Design and I had a discussion in class with my professor and some classmates about a problem represented by the next scenario: Scenario Imagine ...
1
vote
0answers
113 views

Making code more “modular”

As an semi-experienced procedural PHP developer, my OOP still needs a lot of work. I am still working through SOLID principles and other theories and guidelines of OOP, and am stuck with something ...
1
vote
2answers
189 views

Design of 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. ...
27
votes
5answers
5k views

Is overriding concrete methods a code smell?

Is it true that overriding concrete methods is a code smell? Because I think if you need to override concrete methods: public class A{ public void a(){ } } public class B extends A{ @...
46
votes
9answers
7k views

Code Smell: Inheritance Abuse [duplicate]

It's been generally accepted in the OO community that one should "favor composition over inheritance". On the other hand, inheritance does provide both polymorphism and a straightforward, terse way of ...
3
votes
2answers
411 views

Preventing Liskov Substitution violation

I am reimplementing some component and noticed that the original version has a Liskov Substitution violation. It's not all that critical, though I'd like to get rid of it in the new implementation . ...
11
votes
5answers
4k views

Is Liskov Substitution Principle incompatible with Introspection or Duck Typing?

Do I understand correctly that Liskov Substitution Principle cannot be observed in languages where objects can inspect themselves, like what is usual in duck typed languages? For example, in Ruby, if ...
5
votes
6answers
276 views

Rule of thumb for deciding which class a method belongs to

For example, imagine a website which stores results about a certain sport or game, which has a typical "season" structure, such that there's both a Player and a Season class. To retrieve a player's ...
20
votes
4answers
2k views

Do special-cases with fallbacks violate the Liskov Substitution Principle?

Let's say I have an interface FooInterface that has the following signature: interface FooInterface { public function doSomething(SomethingInterface something); } And a concrete class ...
10
votes
5answers
2k views

Is method overriding always a violation of Liskov Substitution Principle? [duplicate]

Overriding a method originally defined in the super class, by definition means this method will do different things when invoked on an object of the base class or an object of the subclass. So does ...
6
votes
2answers
2k views

How does strengthening of pre conditions and weakening of post conditions violate Liskov Substitution principle?

I read that Liskov substitution principle is violated if : Pre conditions are strengthened . Post conditions are eased out. But I don't get fully yet how these two points would violate Liskov ...
22
votes
9answers
4k views

What can go wrong if the Liskov substitution principle is violated?

I was following this highly voted question on possible violation of Liskov Substitution principle. I know what the Liskov Substitution principle is, but what is still not clear in my mind is what ...
33
votes
6answers
9k views

LSP vs OCP / Liskov Substitution VS Open Close

I am trying to understand the SOLID principles of OOP and I've come to the conclusion that LSP and OCP have some similarities (if not to say more). the open/closed principle states "software ...