oop

Using Java generics in interfaces that return collections. Best practice? Pitfalls?

I ran into some code today that I found questionable. Here's a simplified example (not realistic). public interface IListable { //returns first n items from list public ArrayList getFirstNThings(int n); //returns last n items from list public ArrayList getLastNThings(int n); } Then there's an implementor like so: pu...

One-to-Many composition and data retrieval

This is a classic problem that I could never seem to come up with a solution for that I was happy with. What would be considered an OO-elegant and DB-scalable approach to this problem? Employee - Name, Phone, Meta, etc Company - Meta, etc - Employee[] CompanyRepository (RDMBS) - Company GetById(int) - Company[] GetAll() Approach #1...

how should I think in object or how to make the most out of objects?

Hey there, I know the concept of OOP for couple of years and I'm aware of using it and creating lets say not too complicated objects. but I want to understand the OOP way better than the place I am stand right now and use it just like a real pro. actually I'm an independent programmer I have to deal with several languages and platfor...

Should a Form object posses the dual responsibilities of displaying and processing?

I have a prototype with a Form class which auto-generates an HTML form, and now I am plugging some processing functionality into the prototype. Should the same Form class that generates the HTML for the form also process the form? Doing so would make the class have two different, distinct...yet related purposes. Should this be one clas...

Global Javascript Event Handling Object Context

I have the following problem in event handlers in Javascript. I've got an object that has a mousemove event handler like so. function MyObject(){ } functino MyObject.prototype = { currentMousePosition: null, onMouseMove: function(ev){ this.currentMousePosition = this.getCoordinates(ev); }, getCoordinates: functio...

Handling Multiple Class Operations in a Factory

I have the following Factory Method: public function createErrorNotifier($verbose_output = false, $logging = false) { // First we get the handler $errorHandler = $this->buildErrorHandler(); $errorNotifier = $this->buildErrorNotifier(); // We attach the notifier to the handler $errorHandler->setCallback(array($error...

abstract class conflict in php

I have this class: abstract class Hotel { protected $util; function __construct() { $this->util = new Utility(); } function add(Validate $data, Model_Hotel $hotel){} function delete(){} function upload_image(array $imagedetails, $hotel_id){} } and a class that extends it class Premium extends ...

Should I instantiate a collection or inherit from collection?

I've asked myself this question a number of times when creating classes, particularly those involving collections, but I've never come up with a satisfactory answer. It's a OOP design question. For example, in a checkbook register program say I have a class of BankAccount. BankAccounts contain data involving the Name of the account, the...

OOP functionname acting as __construct when its the same name as the class

Bit long title, comes down to this: <?php class error { public function error($errormsg = false, $line = false) { echo 'errormsg: '.$errormsg.' on line: '.$line; } } ?> When i call this class in another file, with for example: <?php $error = new error; ?> It already execut...

How should I refactor my class?

Basically I have a class that sends a SOAP request for room information receives a response, it can only handle one room at a time.. eg: class roomParser { private $numRooms; private $adults; private $dailyPrice; public function parse(){} public function send(){} }; $room = new roomParser( $arrival, $departue ); $...

How do I modelize my two classes knowing one needs the method of the other?

Hello, I have these two classes and the class Retrodoc needs to know the versionPath() to execute its method run($versionId). So what is the best modelization? Do I instanciate Version in the method and then I can use the method getVersionPath()? Thanks in advance. ...

how to measure execution time of functions (automatically) in Python

Hello! I need to have a base class which I will use to inherit other classes which I would like to measure execution time of its functions. So intead of having something like this: class Worker(): def doSomething(self): start = time.time() ... do something elapsed = (time.time() - start) print "doSo...

MVVM: How is the model view supposed to communicate with the data model.

I'm learning about MVVM and one of the things I don't get is how the model and the view model are supposed to communicate. I also don't understand whether they are separate classes, composite classes, or whether the ModelView is supposed to inherit from the model. I need to get some data from a web service, so I think the model should b...

How to find where implementation of a function is located in PHP in this case?

Hello, I was just traversing the workflow of zend framework and cant really find where the function "findByUri()" is located, I found the class it belongs , simply dumping it, but going through the hierarchy of that class(parents , interfaces and so forth) I cant really find it. I found where it is called from .... call_user_func_arra...

How to make a class property private in PHP4?

in PHP4 there is no public,private,etc. So I am wondering if there is some sort of work-around so that I can make a class's property private and only accessible via getter/setter Thanks!! ...

How to model game object rendering and behavior in modular way?

I'm making a Java shoot em up game for Android phones. I've got 20 odd enemies in the game that each have a few unique behaviors but certain behaviors are reused by most of them. I need to model bullets, explosions, asteroids etc. and other things that all act a bit like enemies too. My current design favors composition over inheritance ...

OO Design Question

Looking for opinions on this: I have broken out various responsibilities into separate objects. However, many of these objects have dependencies on each other. All of these objects are adhering to interfaces so I'm not tied to an implementation. I'm concerned about the dependencies between objects and the potential for circular depen...

Serialize & print the entire state of an object while debugging

While debugging an ASP.NET application, I want to get a print-out of the entire state of a very large object. I want all the properties and values in that object and the same for every object-property, recursively. Because the front-end of the application times out after a significant delay, I can't add a watch or use the Immediate wind...

How to model cascading settings in an object hierarchy

Trying to put my head around how to model the notion of default values in an object hierarchy. These default values should apply to all objects in the hierarchy unless an object overrides a setting. If a setting is overridden, then it and all of its children would get the overridden value, but other values would be pulled from up the h...

Design question for highly extensible project - Bearing in mind best practises.

Hi there. Development environment is C# 3.5 with a SQL Server 2008 database and Entity Framework. Imagine you have a class and a table called Sign which represents a physical electronic sign created by a third party which your software needs to control. You also have a class called SignDriver which takes care of actually communicating ...