oop

Can you alter a Javascript function after declaring it?

Let's say I have var a = function() { return 1; }. Is it possible to alter a so that a() returns 2? Perhaps by editing a property of the a object, since every function is an object? Update: Wow, thanks for all the responses. However, I'm afraid I wasn't looking to simply reassign a variable but actually edit an existing function. I am t...

Abstract class - hiding implementation in C++ practice

Recently I've been writing code similar to this: messagehandler.h: #include "message.h" class MessageHandler { public: virtual ~MessageHandler() {} virtual void HandleMessage(Message *msg) = 0: }; persistmessagehandler.h: MessageHandler *CreatePersistMessageHandler(); persistmessagehandler.cpp: #include "messagehandler.h" #...

How to avoid out parameters?

I've seen numerous arguments that using a return value is preferable to out parameters. I am convinced of the reasons why to avoid them, but I find myself unsure if I'm running into cases where it is unavoidable. Part One of my question is: What are some of your favorite/common ways of getting around using an out parameter? Stuff alon...

Does pure composition break OOP concepts ?

class Room{ public: void ColorRoom(){}; }; class House{ public: Room* GetRoom(){return &m_room;} private: Room m_room; }; 1) Room cannot exist without a house, an house "has a" room. (composition) 2) Another way to color room would be to have a method in House that would invoke the ColorRoom in Room method but then t...

Creating a plugin feature in asp.net

I have an interface that others can implement. I want people to be able to create a concrete implementation of the interface, and then be able to drop their .dll into the /bin directory, and then have my asp.net web application use their implementation. Is this possible? Any other ideas on how to make a plugin type architecture so peo...

Reflection Help - Set properties on object based on another object

Hello All, I could use a bit of relection help. I am passing an object into the constructor of another object. I need to loop through the parameter's properties and set the new objects properties based on it. Most, but not all, of the params properties exist in the new object. I have this so far, the basic skeleton. public Disabilit...

What a single sentence consist of? How to name it?

Hi, I'm designing architecture of a text parser. Example sentence: Content here, content here. Whole sentence is a... sentence, that's obvious. The, quick etc are words; , and . are punctuation marks. But what are words and punctuation marks all together in general? Are they just symbols? I simply don't know how to name what a singl...

Importance of protected/private in PHP classes

Usually when I see PHP classes, most of the variables and functions are either private or protected. Because the PHP is executed on the server side, I don't understand why you would need these security features. Are these available for security or am I missing something? ...

Should I be using an object for this JS/PHP interaction? Does this look right?

Part of a site I am building uses a javascript ajax request to hit a PHP script that retrieves, parses, sorts and paginates and returns results from an XML file. I have done this in a pretty straight forward fashion on the PHP side with variables POST variables being retrieved, sanitized and reassigned, SimpleXML loading the file and usi...

Looking for a pure object oriented language

I think object oriented programming is overrated, however I want to learn this paradigm. I have been trying to do this in PHP 5 and C++ with QT 4. Unfortunately, I tend to program in structured way, I do not use much of inheritance nor multiple instances. I think I have to learn a pure object oriented language that force me to use above ...

Implementation of a general-purpose object structure (property bag)

We need to implement some general-purpose object structure, much like an object in dynamic languages, that would give us a possibility of creating the whole object graph on-the-fly. This class has to be serializable and somehow user friendly. So far we have made some experiments with class derived from Dictionary<string, object> using t...

How do I add a method to an object in PHP?

Hello; I've got an Object Oriented library I wanted to add a method to, and while I'm fairly certain I could just go into the source of that library and add it, I imagine this is what's generally known as A Bad Idea. How would I go about adding my own method to a PHP object correctly? UPDATE ** editing ** The library I'm trying to ad...

How do I create a child class of Javascript's Function class?

I would like to create a Javascript class that I can use like so: var f = new myFunction(arg1, arg2); f.arg1; // -> whatever was passed as arg1 in the constructor f(); f instanceof myFunction // -> true typeof f // -> function I can treat it like a normal object, even adding the native Function object to the prototype chain, but I can...

What is the difference between a concrete class and an abstract class?

Hi, I am learning C++, but I am confused about abstract class and concrete class. Some real world examples would be appreciated. ...

Storing objects as variables in a PHP class

Assume you have several arbitrary classes like below: class Foo { $foovar; public function __construct() { $foovar = "Foo"; } public function getFoo() { return($foovar); } } class Bar { $F; public function __construct() { $F = new Foo(); } } My question is is it p...

How to introduce a special case in the API design?

I'm developing API for a library which will be used by a customer. The library should provide single interface to access several remote resources. So, I should create API and several its implementations (correspondent to the number of remote resources). I met the next problem: all resources except one has API for logging in. So, I can ...

How do I add a count property to an item in a collection in Rails?

I have a data model involving Users and Awards, and joined by a user_awards table. class User < ActiveRecord::Base :has_many :user_awards :has_many :awards, :through => :user_awards # awards the user has won end class Award < ActiveRecord::Base :has_many :user_awards :has_many :users, :through => :user_awards end I'd like th...

Is this a problem typically solved with IOC?

My current application allows users to define custom web forms through a set of admin screens. it's essentially an EAV type application. As such, I can't hard code HTML or ASP.NET markup to render a given page. Instead, the UI requests an instance of a Form object from the service layer, which in turn constructs one using a several RDM...

underscores in php function calls

I know that underscores in function names in PHP is used to "implicitly" denote that they are supposed to be private...but I just saw this code: class DatabaseConnection { public static function get() { static $db = null; if ( $db == null ) $db = new DatabaseConnection(); return $db; } private $_handle = null;...

Confused in polymorphism?

Why is overloading called compile time polymorphism and Overriding run time polymorphism in C#? ...