oop

Objects mapping to tables

For a program with an OO front-end and a SQL back-end, can one have each parent class map to its own table and each child class map to it's own table, then use joins in queries to allow returning all the child class's attributes? If so, is it advisable? ...

Law of Demeter and Class Constructors

The Law of Demeter does not prevent passing objects into class constructors. However, it does forbid getting that same object back later and calling a method on it to get a scalar value out. Instead, a proxy method is supposed to be created that returns the scalar value instead. My question is, why is it acceptable to pass an object into...

Architecture/Design of a pipeline-based system. How to improve this code?

I have a pipeline-based application that analyzes text in different languages (say, english and chinese). My goal is to have a system that can work on both languages, in a transparent way. NOTE: This question is long because it has many simple code snippets. The pipeline is composed of three components (lets call them A, B, and C), and ...

When to use events?

At work, we have a huge framework and use events to send data from one part of it to another. I recently started a personnal project and I often think to use events to control the interactions of my objects. For example, I have a Mixer class that play sound effects and I initially thought I should receive events to play a sound effect. ...

how best to refactor two classes with lots of conditional logic?

hi! I have an Event class which holds start and end times for an event. Each Event object can have a number of associated ChildEvent objects representing each recurrence of the parent Event. Each of those classes needs to take a different action based on how they are being edited e.g. Deleting just one Event: Event: make the first ch...

use object created in class constructor in class methods

Hi. Is it possible to use an object that was created during a class' construction within the member methods of that class? Ex <?php include ('AClass.php'); class Auto_Cart { function Auto_Cart() { $aclass = new AClass(); } function DoSomething() { $aclass->amemberfunction(); } } ?> When I call DoSo...

DDD or old fashion ?

We are about to design a site for rentacar reservations using asp.net. There is a change that the application will scale up and I was wondering what if using DDD would help in maintenance and performance. I was wondering on what if there are new similar sites designed using datasets and SPs or DDD. So my friends to DDD or go old fashion ...

Using numbers for names of javascript object elements

Is the following code valid? var i; var objs={}; for (i=0; i <10; i++) { objs.i=new FooObject(); } alert(objs.4.someMethod()); If not, how should it be rewritten to accomplish what I want? ...

How to access functions in child classes?

A child class can access protected functions in parent class,but the parent class can't access protected functions in child class. I'd like to keep both classes as private as possible.The parent class is a form and only once instance is used.All functions in the child class are static,it inherits from the parent class. How is it possib...

Can you declare <canvas> methods within a template in javascript?

Not entirely sure I posed the question in the best way but here goes... I have been playing around with the HTML5 canvas API and have got as far as drawing a shape in the canvas and getting it to move around with the arrow keys. I then tried to move my various variables and functions to a template so I could spawn multiple shapes (that...

.Net class helper method

Is there a way to add a method to a class, but allow it still be inherited by the base class? I have the following public class ListWithRandomize<T> : List<T> { public void Randomize() { // Randomize function} } I'm going to have a bunch of List objects that will need to be randomized. Is it possible to have a List object that I...

Learning object oriented thinking

Hi! I have a problem. My mind isn't working as I wish it would. I'm currently working on a small 2D game-engine in C++, but I am now facing a deamon - I suck at designing a 'system of classes' that actually works. There are a blockade in my mind that disables me from seeing where I should use a class and where I should not. I was readi...

Is Inheriting nested classes possible?

Well,I have a parent class with a nested class declared in the "protected" tab with a protected class variable.In another unit I have a child class,which inherits from the parent class.When I try to access something protected/public from the parent class -it works,but when I try to access something protected from the nested class,it does...

avoiding long class constants as parameters - PHP

example: class Vendor_ClassName_Helper { CONST FIRST_OPTION = 1; CONST SECOND_OPTION = 2; public function __construct($option, $otherArgument) { } } client code: $obj = new Vendor_ClassName_Helper(Vendor_ClassName_Helper::FIRST_OPTION, $var); Any good ways to avoid the long lines (and this is a rather short examp...

VB6 reference to UserControl

I have a variable of type UserControl private at the top of a class. Depending of some condition, one of my two UserControl is displayed. The problem is that I wanted to SET the global private variable of type UserControl to the visible UserControl to have a reference on it for later use. I always got Error Type Mismatch. Private mo_Se...

Is OOP abused in universities ?

I started my college two years ago, and since then I keep hearing "design your classes first". I really ask myself sometimes, should my solution to be a bunch of objects in the first place! Some say that you don't see its benefits because your codebase is very small - university projects. The project size excuse just don't go down my thr...

Clean OO-structure vs. SQL performance

When programming in PHP I always try to create meaningful 'models' (classes) that correspond to tables in the database. I often encounter the following problem: Assuming that I've created a database with two tables: authors and blogs, which both have a corresponding model in my application. Let's say I want to print all the blogs along...

Object Oriented Design with Ruby

What are some of the best practices for OOD with Ruby? Mainly, how should files and code be organized? I have a project that uses several classes and files and I am just wondering how it should all be organized, grouped and included. ...

Where to create the AbstractFactory

In abstract factory you declare a type which is responsible for creating objects. This would prevent requiring switch's like this: if( type == ONE ) { doOne(); } else if( type == TWO ) { doTwo(); } etc. Or the same: switch( type ) { case ONE: doOne(); break; case TWO: doTwo(); break; etc.... } In...

Object Orientated Common Methods: Interfaces, Abstract, or something else.

Hi This is probably a really straightforward answer - but a bit of advice would be appreciated. I have a small system where all of my objects use the same load() and loadMultiple() methods. Exactly the same code in each. Very simple, example below. public static function load($id) { // Instantiate the object $object = new self($id);...