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...
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...
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...
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...
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...
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...
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 ...
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...
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...
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 );
$...
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.
...
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...
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...
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...
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!!
...
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 ...
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...
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...
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...
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 ...