oop

Functional programming: state vs. reassignment

I need help getting my head around the difference between my current OOP notion of state, and the way it would be done in a functional language like Haskell or Clojure. To use a hackneyed example, let's say we're dealing with simplified bank account objects/structs/whatever. In an OOP language, I'd have some class holding a reference ...

How to model this in OO

hello I have a UI-dialog something like this: You must choose a book from a list. Optionally, you can either choose a publisher (another class) from a list or enter the publisher-name as as a string. I think this gives me 3 types as the output from the dialog. book book with publisher-class book with publisher-string How would you...

Best practices for wrapping an external library

Our code base uses several external libraries, in order to save time and focus on developing important features instead of reinventing the wheel. Currently the code is littered with direct usage of the libraries. This means that switching to other libraries that have more-or-less the same features will mean rewriting almost everything f...

Are there any situations where a side effect on a "get" or "calculate" operation is legitimate?

I've just finished a six hour debugging session for a weird UI effect where I found that my favorite framework's implementation of an interface function called "getVisibleRegion" disabled some UI feature (and apparently forgot to restore it). I've filed a bug with the framework, but this made me think about proper design: under what co...

Should Class Helpers be used in developing new code?

Delphi 8 introduced Class Helpers for the purposes of mapping the VCL/RTL to the .NET object hierarchy. They allow injecting methods into an existing class without overriding the the class or modifying the original. Later versions of Delphi found class helpers improved and they were ported to Win32. In the help it says "they should no...

What is the best way to access properties from the same class, via accessors or directly?

This is something I'm not much consistent about and always curious about what other people do. How do you access internal properties (private or public)? For example you've got this property : Private _Name As String Public Property Name() As String Get Return _Name End Get Set(ByVal value As String) _Nam...

How do you explain OO to new programmers?

My relative is studying programming and has a hard time understanding classes. He has trouble understanding for example that you need to instantiate it, that methods cannot access variables in other methods and if you change a variable in one instance of a class it doesn't change for other instances. I've tried to use analogies like a c...

What is the best way to emulate "classes" in Javascript? (with or without a framework)

Update: I've wikified this so it can become a more useful resource. What is the best way to emulate classes (and namespaces) in Javascript? I need to create a Javascript library and have limited experience with the language. I always thought that it had native support for classes, but it is less related to Java than I had assumed. I...

Can I extend a class using more than 1 class in PHP?

If I have several classes with functions that I need but want to store separately for organisation, can I extend a class to have both? i.e. class a extends b extends c edit: I know how to extend classes one at a time, but I'm looking for a method to instantly extend a class using multiple base classes - AFAIK you can't do this in PHP b...

Is partial class template specialization the answer to this design problem?

Say you have a class who's job it is to connect to a remote server. I want to abstract this class to provide two versions, one that connects through UDP and the other through TCP. I want to build the leanest runtime code possible and instead of using polymorphism I am considering templates. Here is what I'm envisioning but I'm not sure i...

OOP design question - keeping track of many similar things

I'm designing a Data Access layer for an C#/ASP.net application and I have a question regarding the treatment of parameters in sql queries. At the moment, when a query needs a dynamically set parameter for the Where clause I have to (1) define a variable to hold the value, (2) add a new QueryStringParameter to the SqlDataSource's Select...

unidentified syntax in domain object constructor

Can someone help me identify what the purpose of this unidentified syntax is. It is an extra little something in the constructor for this object. What I'm trying to figure out is what is the "< IdT >" at the end of the class declaration line? I think that this is something I would find useful, I just need to understand what it is why so ...

Calling parent function from derived child

How do I call the parent function from a dervied class using C++? For example, assume I have a class called parent, and a class call child which is derived from parent. within each there is a print function. In the defintion of the child's print function I would like to make a call to the parents print function. How would I go abo...

Why are unnamed namespaces used and what are their benefits?

I just joined a new C++ software project and I'm trying to understand the design. The project makes frequent use of unnamed namespaces. For example, something like this may occur in a class definition file: // newusertype.cc namespace { const int SIZE_OF_ARRAY_X; const int SIZE_OF_ARRAY_Y; bool getState(userType*,otherUserType*)...

Design pattern for methods in another class

I am looking for a specific desgin pattern. For example i have an article class, clsArticle. This class contains member variables like Id, title, author, article, and so on. Imagine i want to show all the articles in a list. So somewhere i have to create a method getAllArticles(). Since clsArticle is not responsible for getting all the ...

About consistensy in the powershell scripting language, using .NET types

If I want to create a .NET object in the powershell I write something like the following: [System.Reflection.Assembly]::LoadWithPartialName("System.Xml") | out-null" $doc = new-object -typename System.Xml.XmlDocument" If I want to call a static .Net method I use a command similar to the following line: $path = [System.String]::Format...

Best solution for __autoload

As our PHP5 OO application grew (in both size and traffic), we decided to revisit the __autoload() strategy. We always name the file by the class definition it contains, so class Customer would be contained within Customer.php. We used to list the directories in which a file can potentially exist, until the right .php file was found. T...

Can I specify a non strict method requirement for child classes? [PHP]

I have a base class in which I want to specify the methods a child class must have, but not implement them itself. However, the methods in a child class may have a different number of paramaters to the definition in the base class. Having tried this with an abstract method, php doesn't allow this. Is it possible? ...

Which development skills have you acquired after 7-10++ years of experience in OO development ?

Some development skills, like refactoring operations, feel like they have an almost unlimited pontential for learning - only the fool will say he's finished learning that. Other skills are bound to specific tools, and being good developers we learn new tools most of the time. But some skills are related to how you think about code and ...

How would you design the the control tree/hierarchy without inheritance?

I am aware of the responses at Prefer composition over inheritance and am aware of the merits of composition over inheritance. But there are cases where inheritance does have a good role to play. It's the incorrect use of inheritance hierarchy that causes all the issues related to reuse. Take the example of the following controls......