oop

OO behaviour for an ER database (One-to-many relationship for multiple tables)

I'm designing a document management system for a school (SQL & .NET). The school has various data it would like to store, such as personnel, pupils, financials etc. The system should be able to attach a document to any of the records in the system irrespective of its type (personnel, pupil...) A typical ER way of doing this would be to ...

NHibernate compromising domain objects

I'm writing an ASP.NET MVC application using NHibernate as my ORM. I'm struggling a bit with the design though, and would like some input. So, my question is where do I put my business/validation logic (e.g., email address requires @, password >= 8 characters, etc...)? So, which makes the most sense: Put it on the domain objects the...

Is frequent downcasting in class hierarchy always evil?

From what I`ve learned, it is no good if you frequently use downcasting in class hierarchies. I agree with that, but what are exceptions from this rule if any? This is where my design of graphical editor shows thin: I have two hierarchies, where geometric figures hierarchy decoupled from graphic primitives one. Like this: public class G...

As3 OOP game structure (class architecture)

Game description: A quiz with different levels and different types of visual questions for each level. OOP so far: GameBoard (where one answers questions), Dialog, HighScore, Controller/LevelController? I have a document class called Controller which initializes the game: public function Controller() { initGame(); } function ...

Is it code-smelly to have empty classes in the middle of a class hierarchy?

I sometimes end up with a class hierarchy where I have an abstract base class with some common functionality and a couple of implementing classes that fall into two (rarely more) groups which I want to treat differently in some cases. An example would be an abstract tree node class and different branch and leaf implementations where I wa...

Subclasses causing unexpected behavior in superclasses — OO design question

Although I'm coding in ObjC, This question is intentionally language-agnostic - it should apply to most OO languages Let's say I have an "Collection" class, and I want to create a "FilteredCollection" that inherits from "Collection". Filters will be set up at object-creation time, and from them on, the class will behave like a "Collect...

Friend methods/classes for AS3 packageless classes

Hi I'm wondering if I can have a packageless () AS3 class call a private method on the main class in the file. For example: package demo { public class MyDemoClass { var helper:FriendlyHelperClass = new FriendlyHelperClass(this) } private function methodToCall():void { ... } } public class Frien...

Best Practice: Abstract data via get/set or allow access to the variable?

Hi folks, I was writing some python classes the other day, and created a class like this: class Option: Name = "" Description = "" Criteria = {} def __init__(self, name, descr): self.Name = name self.Description = descr def addCriteria(self, cname, ctype): ... In my program, I was accessing the data in the class direc...

When to use custom c# events

When is it appropriate to raise an event in C#? As an example, in our system we have data objects being sent to us, say 50 per minute, from an external system. Upon receiving a data packet, we need to have it processed by another object. Would an event or a simple method call be better to use in this situation? An event seems like a ...

Java: Using one class to generate objects of another

I have two classes. SpeciesReader takes files and parses them. Species stores certain data about a species, which has been parsed from the file. Currently, I have a method: SpeciesReader.generateSpecies(), which uses the file with which it was instantiated to create a Species object. Is this bad practice/design? Should I somehow find a ...

Java: Using one function to return a few different types of value

I have a readData() function that reads files a returns a few different objects of parsed data. Right now, the return type of readData() is Object[]: Object[] data = readData(); MyGenome genome = data[0]; Species[] breeds = data[1]; //etc This feels awkward. Is there a better way to return this data? I don't want to have separate func...

Overriding equals method

In OO parlance what is meant by overriding equals method and getHashCode ? ...

What's the difference between "use case", "User Story" and "Usage Scenario"?

Is there an exact, but simple and understandable defintion of the distinction between "use case", "User Story" and "Usage Scenario"? there are quite a bunch of explanation, but right now, I see no one that explains the differences in a single sentence, or two... (e.g. http://c2.com/cgi-bin/wiki?UserStoryAndUseCaseComparison very long...

Static classes in Delphi (Win32)

Is it in Delphi (Win32) possible to declare a whole class (not only a function of the class) as static? ...

Design: When the line between domain objects and service objects isn't clear

This question is, at it's core, a design question. I'll use a Java/JEE example to illustrate the question. Consider a web-mail application which is built using JPA for persistence and EJB for the services layer. Let's say we have a service method in our EJB like this: public void incomingMail(String destination, Message message) { ...

General Command pattern and Command Dispatch pattern in Python

I was looking for a Command pattern implementation in Python... (According to Wikipedia, the command pattern is a design pattern in which an object is used to represent and encapsulate all the information needed to call a method at a later time. ) The only thing I found was Command Dispatch pattern: class Dispatcher: ...

Indexer on IList

This is probably something I'm overlooking in C# inheritance, but I was trying to build a class that implements IList(The System.Collections version, not generics) The compiler complained that I didn't implement an indexer, but I was looking at CollectionBase, which also implements IList, and it doesn't appear to expose an indexer either...

How to return often occurring error in object oriented environment?

Hi, assume you have a function that polls some kind of queue and blocks for a certain amount of time. If this time has passed without something showing up on the queue, some indication of the timeout should be delivered to the caller, otherwise the something that showed up should be returned. Now you could write something like: class ...

How to pass an Interface object to a WebMethod?

I have a .Net web service with web method which take a Interface object as parameter, whenever I try to access the method I get exception saying : Cannot serialize member Product IProduct because it is an interface. Any suggestions to solve the problem ?? [WebMethod] Public double CalculateTotal(IProduct product, int Quantity) { ret...

Is it OK if objects from different classes interact with each other?

Hi, I just started to use the object oriented programming in Python. I wander if it is OK if I create a method of a class which use objects from another class. In other words, when I call a method of the first class I give an object from the second class as one of the arguments. And then, the considered methods (of the first class) can m...