oop

Interfaces: Why can't I seem to grasp them?

Could someone please demystify interfaces for me or point me to some good examples. I keep seeing interfaces popup here and there but i havent ever really been exposed to good explanations of interfaces or when to use them? I am talking about interfaces in contect to interfaces vs abstract classes ...

Should I be more concerned with coupling between packages or between units of distribution?

I have been looking at metrics for coupling and also look at DSM. One of the tools I've been using looks at coupling between 'modules' with a module being a unit of distribution (in this case a .net assembly). I feel that I should be more interested in looking at coupling between packages (or namespaces) than with units of distribut...

Is OOP & completely avoiding implementation inheritance possible?

I will choose Java as an example, most people know it, though every other OO language was working as well. Java, like many other languages, has interface inheritance and implementation inheritance. E.g. a Java class can inherit from another one and every method that has an implementation there (assuming the parent is not abstract) is in...

A way of casting a base type to a derived type

I'm not sure if this is a strange thing to do or not, or if it is some how code smell...but I was wondering if there was a way (some sort of oop pattern would be nice) to "cast" a base type to a form of its derived type. I know this makes little sense as the derived type will have additional functionality that the parent doesn't offer wh...

What's the difference between Polymorphism and Multiple Dispatch?

...or are they the same thing? I notice that each has its own Wikipedia entry: [1] [2], but I'm having trouble seeing how the concepts differ. Edit: And how does Overloading fit into all this? ...

Chaining Static Methods in PHP?

Is it possible to chain static methods together using a static class? Say I wanted to do something like this: $value = TestClass::toValue(5)::add(3)::subtract(2)::add(8)::result(); . . . and obviously I would want $value to be assigned the number 14. Is this possible? Update: It doesn't work (you can't return "self" - it's not an ins...

Bad OO design problem - I need some general functionality in Java but don't know how to implement it

Hello, I'm developping a small UML Class editor in Java, mainly a personal project, it might end up on SourceForge if I find the time to create a project on it. The project is quite advanced : I can create classes, move them around, create interfaces, create links, etc. What I'm working on is the dialog box for setting class/interface...

Best design for lookup-and-possibly-change method

I am designing a class that stores (caches) a set of data. I want to lookup a value, if the class contains the value then use it and modify a property of the class. I am concerned about the design of the public interface. Here is how the class is going to be used: ClassItem *pClassItem = myClass.Lookup(value); if (pClassItem) { // it...

Which design is better for a class that simply runs a self-contained computation?

I'm currently working on a class that calculates the difference between two objects. I'm trying to decide what the best design for this class would be. I see two options: 1) Single-use class instance. Takes the objects to diff in the constructor and calculates the diff for that. public class MyObjDiffer { public MyObjDiffer(MyObj ...

Using property() on classmethods

I have a class with two class methods (using the classmethod() function) for getting and setting what is essentially a static variable. I tried to use the property() function with these, but it results in an error. I was able to reproduce the error with the following in the interpreter: >>> class foo(object): ... _var=5 ... de...

MVC model design / inheritance

Forgive the vague title, I wasn't sure how to describe it. If you have a generic model "Archive", how do you show different views/forms based on a user selected 'type'? For example, the user creates a new "Archive", then gets the choice of video, book, audio etc. From there they get different forms based on the archive type. Or would ...

Expressing an is-a relationship in a relational database

I was wondering if there is a clean way to represent an is-a relationship as illustrated by this example: This DB stores recording times for three types of programs: movies, game shows, drama. In an object oriented sense each of these is-a program. Each of these subclasses have different properties. Here are the tables (fk prefix indica...

What is the best way to implement a singleton pattern class in Actionscript 3?

Since AS3 does not allow private constructors, it seems the only way to construct a singleton and guarantee the constructor isn't explicitly created via "new" is to pass a single parameter and check it. I've heard two recommendations, one is to check the caller and ensure it's the static getInstance(), and the other is to have a private...

Should constructor variables pass direct to private fields or properties?

Now this is .NET but I am sure the principal should apply to all OOP language, to simplify I take .NET as an example: R# usually creator constructor and passing incoming variable to private field, which for me mi tend to pass it to Property. Any opinion on how the different and what is the best practice for that? ...

What are the benefits of OO programming? Will it help me write better code?

I'm a PHPer, and am not writing object-oriented code. What are the advantages of OO over procedural code, and where can I learn how to apply these ideas to PHP? ...

Best place to Sort a List of Tasks

Hi, Im building a web application which is a process management app. Several different employee types will be shown a list of Tasks to do and as each one completes a task then it is moved on to the next employee to work on. The Task hierarchy is Batch > Load > Assembly > Part > Task. There are currently 8 rules for determining which T...

How do I prevent using the incorrect type in PHP?

PHP, as we all know is very loosely typed. The language does not require you to specify any kind of type for function parameters or class variables. This can be a powerful feature. Sometimes though, it can make debugging your script a painful experience. For example, passing one kind of object into a method that expects a different kind...

How is a real-world simulation designed?

I am fascinated by the performance of applications such as "Rollercoaster Tycoon" and "The Sims" and FPS games. I would like to know more about the basic application architecture. (Not so concerned with the UI - I assume MVC/MVP piriciples apply here. Nor am I concerned with the math and physics at this point.) My main question deals ...

Using "final" modifier whenever applicable in java

In Java, there is a practice of declaring every variable (local or class), parameter final if they really are. Though this makes the code a lot more verbose, this helps in easy reading/grasping of the code and also prevents mistakes as the intention is clearly marked. What are your thoughts on this and what do you follow? ...

MVC, where do the classes go?

My understanding of the MVC is as follows (incase it's horribly wrong, I am afterall new to it) Models are the things that interface with the database Views are the design/layout of the page Controllers are where everything starts and are essentially the page logic I'm using CodeIgniter but I would hazard a guess it's not just limite...