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 ...
1
vote
1answer
47 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 ...
1
vote
0answers
37 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 ...
7
votes
1answer
446 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(...
5
votes
3answers
217 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 ...
1
vote
1answer
78 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: http://codereview....
3
votes
1answer
177 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 ...
4
votes
3answers
142 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 ...
3
votes
1answer
234 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
64 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
286 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
206 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 ...
-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
54 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 ...
-1
votes
2answers
109 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 ...
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 ...
2
votes
2answers
95 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
186 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 ...
2
votes
3answers
112 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 ...
0
votes
1answer
144 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 ...
3
votes
3answers
98 views

Ways to structure a program with 2 states

I'm working on some sort of a Level Editor but I'm not quite sure how I want to handle the two different states: The Editor state and the Player state. In this first state game elements can be moved ...
0
votes
1answer
120 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 ...
5
votes
3answers
120 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)) ;;...
1
vote
1answer
137 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 ...
0
votes
1answer
149 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 $...
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 ...
1
vote
0answers
114 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 ...
0
votes
2answers
74 views

What are 'good' cases for subtype overloads

To explain what I mean, I'm going to give an example of a bad case for a subtype overload. Let's say we have a community of people. And depending on what kind people are in our community, our ...
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{ @...
4
votes
4answers
308 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
119 views

Design Pattern for Object Updates

I have a "Product" class that has some ID, and multiple other fields, and a function updateProduct(id, Product update). The intention is that "update" only contains the changed information - other ...
-1
votes
3answers
185 views

Modularity vs Polymorphism (OOD main concepts)

Booch gives 4 main concepts (principles) of OOD (see his book Object-oriented analysis and design with applications ): Abstraction Encapsulation Modularity Hierarchy Usually we encounter to these ...
0
votes
2answers
260 views

Without using Singletons, what is a good way to manage a global resource? [duplicate]

Unlike many libraries SDL and OpenGL are designed to provide global resources; you can access them at any time from any class. There are justifications for this: They are written in C, meant to be ...
1
vote
1answer
105 views

Should “magic” getter functions be used for dynamically calculated values or just existing properties?

For example, if I had a Customer class and wanted to get all orders by them. Would it be better to do: class Customer{ public function getOrders(){ return results from db query } } .....
1
vote
4answers
273 views

Can the circle-ellipse problem be solved by reversing the relationship?

Having Circle extend Ellipse breaks the Liskov Substition Principle, because it modifies a postcondition: namely, you can set X and Y independently to draw an ellipse, but X must always equal Y for ...
-2
votes
3answers
182 views

Is it possible to have private or protected objects in Java? Or are all objects considered public?

Is it possible to have private objects? For example, when you instantiate an object (classType object1 = new classType()), can that be private or protected or is it always public?
0
votes
1answer
76 views

How do you write super() in the UML format?Is it correct to write super(parameter: type): return type in the UML methods section?

Suppose you write a subclass that extends to a certain class and in that subclass, you use the super() method for your constructor. Would you write "super(parameter: type): return type" in the UML?
2
votes
1answer
212 views

For Object Oriented Programming purists, are @annotations heresy?

Philosophical Question: An issue that occurred to me is that especially when using frameworks like Spring or Hibernate ( which are everywhere in industry), we have annotate everything. This is ...
5
votes
6answers
282 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 ...
0
votes
1answer
127 views

Design patterns for ERP software with clients and web service

I'll will make ERP software for managing data for business activities. The solution must have two big parts: a WPF application for all the clients and an ASP MVC Web API application for all the client....
6
votes
3answers
399 views

Best practices for using public, protected, private?

Is it fair to say that it is good practice to default everything to private up front when coding something? And then only upgrade it to protected if a subclass needs it, or public if another class ...
1
vote
2answers
156 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 { ...
7
votes
3answers
577 views

Should every object know how to present/draw themselves?

David West in his book Object Thinking (chapter 10, section 1, sub-section 2) proposed that in an ideal OO environment, every objects should be capable of presenting themselves upon request; be it to ...
1
vote
2answers
82 views

Is it good design to log something related to an object from the callee?

I am designing a class whose object is instaniated with a user idn which creates a pdf with that user specific details. It should log something depending on success or failure which can be determined ...
0
votes
5answers
255 views

Is there a better way to debug while avoiding getters/setters?

I'm thinking about how to debug better without using Getters/Setters. If it helps, I program using xcode. Many answers in Stack Exchange have argued against Getters/Setters for lack of encapsulation (...
4
votes
1answer
46 views

Logging multiple objects for various reasons, then grouping by that reason

I'm having trouble cleaning up my code, and was wondering if there was any sort of pattern that I'm not aware of that can help me in this situation. I need to process a list of objects in various ...
3
votes
2answers
224 views

Using MVC style, where is the best place to put SQL functionality?

I am wondering about best practices here. MVC (Model - View - Controller) patterns involve separating components of your program that model the data, manipulate those models, and display those ...
5
votes
4answers
313 views

Why instantiate an object to a Base class rather than a specific Sub class?

For example: URL blogFeedUrl = new URL("http://manishmaharzan.com.np/getJSON/json.json"); HttpURLConnection connection = (HttpURLConnection) blogFeedUrl.openConnection(); connection.connect(); ...
1
vote
1answer
84 views

Split class into two or leave as one

I have the following class: internal class LeaveRequest : ServiceBase { private const string InvalidRequestMessage = "Specified Request does not exist"; private const string ...
0
votes
2answers
83 views

What is the accepted practice for handling numeric conversions under OOP?

I am making a weather app that involves temperatures. You can change between Kelvin, Celsius, and Fahrenheit just for fun. However, temperature figures get used all over the place in different ways. ...