oop

Proper OO modelling of correspondences

Something keeps showing up in my programming, and it is that two things are the same from some viewpoint, but different from another. Like, imagine you build a graph of rail stations, connected by trains, then the classes Vertex and RailStation are sometimes the same, other times not. So, imagine I have a graph that very much represent...

How can I copy a NetStream Object?

I'm using BulkLoader to load an array of 10 or so FLV files. I want to be able to use and control these FLVs throughout my app independently. So for instance, FLV_1 may be displayed in duplicate but I want to pause one instance and play the other in tandem. I would like to pass the NetStream object around to other Video objects and di...

In Java, why super-class method can't access protected or private methods/variables from sub-class instance?

Let's start from another behavior: even if you declare method/variable as private, another instance of the same class can access it. It's OK I can live with it. I call these class private and not instance private. Now the question part: For example, in runtime I want to be able to check that all String variables in this class are not nu...

Should multiple service layer objects share a DAO?

I have a Contact class that contains a PortalAccount object. When I want to create a "Portal Account" for a contact, an account is created remotely on a portal application using soap/axis and then the contact's portalAccount is populated and the contact is saved (local database holds information about the remote account, like user id an...

If I have limited time to learn a few design patterns, which ones should I learn?

If I have limited time, but I want to start learning a few design patterns, which ones should I learn first? ...

Training a Junior Developer

I'm training a Junior developer. I would like to assign him with the task of designing and building an object oriented application. Are there any non-trivial sample exercises on the web which include good description of a problem and a suggested architecture diagram? ...

Should an object write itself out to a file, or should another object act on it to perform I/O?

NOTE: Sorry for the long question! I'm trying to understand some key areas behind object orientation and I couldn't decide one way or another about my particular question. Let's say I have an object full of lovely data. Class bob. Bob myBob = new Bob("This string is data"); Let's say I want to save the contents of myBob to an xml f...

Modeling question: Lists that depends on each other, but can be specialized entries?

Hi all Trust me, I've put a lot of thought into this problem before asking here, and I think I got a solution, but I'd like to see what you guys can come up with before settling for my own :) SCENARIO: In the domain we got 3 entities: A treatment, a beautyshop and an employee. A beautyshop can hire 0 to many employees. Now, a beautysa...

When is it OK for an abstract base class to have (non-static) data members?

I guess the question title sums it up. Is there a time when it would be considered good design for an ABC to have data members? I have been wondering if there is a situation where this is OK. The only ones I can come up with all are static, and even then it's kind of a stretch. ...

Singleton pattern - doubt in Head First Design Patterns book

Hi all, On page 175, there is an example of Chocolate Boiler class. Something like this: public class ChocolateBoiler { private boolean empty; private boolean boiled; public ChocolateBoiler { empty = true; boiled = false; } // and then three methods to fill, drain and boil which changes the // status...

Chain-calling parent constructors in python

Consider this - a base class A, class B inheriting from A, class C inheriting from B. What is a generic way to call a parent class constructor in a constructor? If this still sounds too vague, here's some code. class A(object): def __init__(self): print "Constructor A was called" class B(A): def __init__(self): ...

Is there any programming language that accept this?

Suppose I have a class like this, in pseudo-code: public class someClass { public void doSomething() { someClass aux = new someClass(); // here something is done to alter the internal structures of aux . . this = aux; } } The attribution "this = aux", would return an error since it's no...

Object Oriented Javascript best practices ?

I'm finding myself coding a big project in Javascript. I remember the last one was quite an adventure because hacky JS can quickly becomes unreadable and I want this code to be clean. Well, I'm using objects to construct a lib, but there are several ways to define things in JS, implying important consequences in the scope, the memory ma...

What are the advantages of using a concept like IStartable?

Instead of using an interface like this: public interface IStartable { void Start(); void Stop(); } I usually just make the constructor of an object run the Start() code, and implement IDisposable so that the dispose method runs the Stop() code. Is it just a matter of style? Or am I missing something important by not having s...

In a method that performs C in CRUD, what should it return ?

Imagine an interface with a method to create objects of type Address. The entities involved here are irrelevant. /** * @throws IllegalArgumentException if addy is null or invalid * @throws PersistenceException if db layer encounters a problem */ Object addAddress( Address addy ); addAddress inserts the domain object into the databa...

Rewriting a midsize application in OO.

What are some apraoches i can take to rewrite fairly large procedural php roughly 2000 lines of code app as an oo app. And should i even try to do so, or should i build on top of the existing app? I wrote it when i was learning programming and i now i want to expand it. ...

What is the advantage of having this/self pointer mandatory explicit?

What is the advantage of having this/self/me pointer mandatory explicit? According to OOP theory a method is supposed to operate mainly (only?) on member variables and method's arguments. Following this, it should be easier to refer to member variables than to external (from the object's side of view) variables... Explicit this makes it...

Python: Inheriting from Built-In Types

Hi fellow Pythonistas, I have a question concerning subtypes of built-in types and their constructors. I want a class to inherit both from tuple and from a custom class. Let me give you the concrete example. I work a lot with graphs, meaning nodes connected with edges. I am starting to do some work on my own graph framework. There is ...

Is it a good idea to divide every graphic shape in two parts - its geometry and rendering components?

I am writing a simple graphic editor for a university project using C#. I created a hierarchy where every type of shape - circles, rectangles, ellipses, ... - are inherited from a base class Shape, it contains a shape color as a protected field. public abstract class Shape { protected Color color; public Shape(Color c)...

How do I make a constuctor available to only the factory class?

Ok, the question might not be crystal clear. Let me give some details: Let's say I have an Shoe (CShoe) object factory class called CFactory. CFactory is a singleton class that creates and stores all instanciated shoes using a simple hashmap. It is then accessed through static methods to use the created objects. Is there a way to force...