oop

When to use delegation instead of inheritance?

Could someone please explain when would I want to use delegation instead of inheritance? ...

How to handle errors for a facade method that performs many disparate background changes ?

Imagine I have a service that looks like this: public interface MyAccountService { boolean create( String user ); } The method create performs several changes, namely (for discussion sake): adds a message into a Queue adds a row into several tables creates a LDAP account etc... Currently I collapse all the error messages into ...

Why is this cast not possible?

the title says it all ... interface IFolderOrItem<TFolderOrItem> where TFolderOrItem : FolderOrItem {} abstract class FolderOrItem {} class Folder : FolderOrItem {} abstract class Item : FolderOrItem {} class Document : Item {} now i'm trying to do sth like this: class Something { IFolderItemOrItem<Item> SelectedItem { get; s...

a problem during init in constructor -- what's next?

C# noob question... I'm taking a few arguments in a class constructor to initialize some private variables. What should I do when the data passed in is not what I expect (wrong string length, numbers out of expected range, nonexisting path, stuff like that..)? Throw an exception? Add "everything went ok" flag? how is it usually done? ...

Typecast or convert method?

I have a container class with parameters which come from different kinds of configuration files (text or xml for example). So I made a class for textConfigurationFiles and a class for xmlConfigurationFiles (I think I will implement an interface IConfigFile for this later). The initialisation of my container class looks like the followi...

What should go into a top level namespace?

What should go into the top level namespace? For example, if I have MyAPI.WebLogic, MyAPI.Compression, etc. If I put classes into the top level namespace, am I violating the principle of encapsulation? ...

Extending Python's builtin Str

I'm trying to subclass str, but having some difficulties due to its immutability. class DerivedClass(str): def __new__(cls, string): ob = super(DerivedClass, cls).__new__(cls, string) return ob def upper(self): #overridden, new functionality. Return ob of type DerivedClass. Great. caps = super(D...

Where should i set my db object in my model ? (MVC)

I would like to know where is the best place to set my db object with my model. Should I hard coded it since my model should be designed for one project, so i set it inside my constructor or wherever i do initialization ? or Should I pass my db object to my constructor when instancing my object ? What is the best way, i mean from exper...

Is this a proper MonoState Design?

I have a Person Class and based on some help I recieved in this post. http://stackoverflow.com/questions/825617/passing-objects-and-the-singleton-pattern/825820 I have a CurrentPerson class around(??) it and I access the data thru that. I think I understand how this is supposed to work but it seems that I don't have it quite right....

How to deal with inept management

A project I was working on has finished, so I've been moved on to some new tasking at my employer. The previous work was very agile, small team, progress over procedure, etc etc. So anyway, the new project I'm on - I find myself confused on how to deal with management. They have no real understanding of object oriented programing , cu...

Call a method in the initiator class from the instantiated class obj-c

I have a button class - when the button is clicked, the playFile method of the MyAudio class is called. So my question is, its trivial to call the playFile method from the button class, but how do I call the method displayStopButton from the initiator class? button class - (void)myButtonClicked: (id)sender { [MyAudio playFile]; } ...

Working with a hashtable of unknown but similar objects (C#)

I have a hash table which can contain any number of objects. All of these objects implement some similar methods / properties and some of their own. For example all objects in the hashtable may have a method called PrintText taking a single parameter of type string. All the objects are however instantiated from different classes. Is it...

When should I use enhanced record types in Delphi instead of classes?

Delphi 2006 introduced new capabilities for records, making them more 'object-oriented'. In which situations is the record type more appropriate for a design than a class type? Which advantage does it have to use these record types? ...

Is subclassing in Objective-C a bad practice?

After reading lots of blogs, forum entries and several Apple docs, I still don't know whether extensive subclassing in Objective-C is a wise thing to do or not. Take for example the following case: Say I'm developing a puzzle game which has a lot of elements. All of those elements share a certain amount of the same behaviour....

OOP: good class design

My question is related to this one: Python tool that builds a dependency diagram for methods of a class. After not finding any tools I wrote a quick hack myself: I've used the compiler module, I've parsed the source code into an Abstract Source Tree and I've walked it to collect dependencies between class methods. My script generated an...

How does this "Programming to Interfaces" thing work?

I like the idea of "programming to interfaces" and avoiding the use of the "new" keyword. However, what do I do when I have two classes that have the same interface but are fundamentally different to set up. Without going into detail about my specific code, I have an interface with a method, "DoStuff". Two classes implement this interfa...

Is it better to externalize object creation from XML or to do it from the constructor?

Hi I have some PHP classes I am creating from XML config. What I would like to know is this: Am I better off (from an object-oriented standpoint) having factory methods to create those classes from XML or passing in XML to the constructor to create the classes? The factory approach has the advantage of separating construction from usa...

BASIC Object-Relation Mapping question asked by a noob

I understand that, in the interest of efficiency, when you query the database you should only return the columns that are needed and no more. But given that I like to use objects to store the query result, this leaves me in a dilemma: If I only retrieve the column values that I need in a particular situation, I can only partially po...

C# OO Design Question

I have a windows form app written in C#. the main_form class instantiates an AccessProcess named AccessProcessWorker which is a class that inherits from BackgroundWorker, then main_form then initializes Process with the following code AccessProcessWorker.DoWork += new DoWorkEventHandler(processWorker.worker_DoWork); Acc...

"Diffing" objects from a relational database

Our win32 application assembles objects from the data in a number of tables in a MySQL relational database. Of such an object, multiple revisions are stored in the database. When storing multiple revisions of something, sooner or later you'll ask yourself the question if you can visualize the differences between two revisions :) So my q...