oop

Private Methods in a Mootools Class

I'm relatively new to using oop in Javascript, and I'm wondering what the best practice is for private methods. Right now, I'm using mootools to create my classes and I'm simulating private methods by prefixing them with an underscore and forcing myself not to call the method outside of the class. So my class looks like: var Notifier ...

C++ inheritance/template question

I have two classes, point and pixel: class point { public: point(int x, int y) : x(x), y(y) { }; private: int x, y; } template <class T> class pixel : public point { public: pixel(int x, int y, T val) : point(x, y), val(val) { }; private: T val; } Now here's my problem. I want to make ...

Dynamically Create Instance Method in PHP

I'd like to be able to dynamically create an instance method within a class' constructor like so: class Foo{ function __construct() { $code = 'print hi;'; $sayHi = create_function( '', $code); print "$sayHi"; //prints lambda_2 print $sayHi(); // prints 'hi' $this->sayHi = $sayHi; } } $f = new Foo; ...

Weird Python behaviour - or am I missing something

The following code: class House: links = [] class Link: pass class Villa(House): pass if __name__ == '__main__': house = House() villa = Villa() link = Link() house.links.append(link) print house.links print villa.links results in this output: [<__main__.Link instance at 0xb65a4b0c>] [<__main_...

PHP vs OO PHP - Which one to use?

I'm developing a web system using regular PHP. This was my first experience with PHP sothe code is not legible nor clean. It mixes some many html code with PHP. I'd say I have already done half of the code. What are the real advantages of the Object-oriented PHP. The website is about books and book authors, using mysql and apache. So it...

Adding features to code bases which are in dire need of refactoring

I am developing on a system that is a bit difficult to work with. It is 99% undocumented, does not follow best practices and is fairly difficult to understand (globals galore, methods spanning 50 lines, eval abuse, etc.). Unfortunately, I am fairly new to the code base and I need to add functionality. I am sure there is code in there th...

PHP classes and static variables - Should I use __destruct() ?

I have a class that's similar to the following: class Person { private static $_sqlData; public function __construct($id) { if (!self::$_sqlData) { self::$_sqlData = // GET THE DB STUFF } } public function getName() { return self::$_sqlData['name']; } } This has bee...

what will be the next big programming paradigm shift

object orientation was the last big paradigm shift I remember. What do you think will be the next big thing in programming paradigms and programming in general? Edit: I was actually listening to Jaron Lanier interview and he was talking about how in the future we would stop worrying idiosyncrasies and the little tidbits about programmi...

How to transfer object from one php file to another php file

hello, i have a query that, how can i transfer an object from php file A to php file B?. but i know a solution using session.But what i need to know is, is their any other method to transfer object between php files other than session? ...

Help me to avoid multiple inheritance aka. help me to get proper oo design.

I have two classes LightA and LightB. I have the source code of LightB but not that of LightA. I extended LightB with LightDimDip. ie LightDimDip:extends LightB. Now I need to apply DimDip feature to lightB also. Can any one suggest good OOP design. Once again I remind you people that I cannot modify LightA. ...

PHP CLASS - public vs private

Possible Duplicate: What is the difference between a private and public function? what is diff between public class and private class ...

Event trigging object method loses the object

Hi. I'm not very used to javascript's prototyping syntax so this might be very simple. function MyClass(){ this.init = function(input){ this.input.onkeyup = function(){ this.change(); } } } Obviously I've left some things out here, but this.input refers to an HTML input element. The problem here is that this...

OOPS query using c#

I have some doubt to implementation of class and interface I have 2 class like this Public Class A:IFinal { private string name=string.Empty; A() { name = "Pankaj"; } public string MyName() { return name; } public string YourName() { ...

Using constructors on the Sub New() for a CCW

I'm trying to create a COM Class Library for my VBA Project and one of the limitations I've seemed to have stumbled across is using constructors on the New() subroutine. After creating the new COM class a Public Sub New() is created with the following comments ' A creatable COM class must have a Public Sub New() ' with no parameters, ...

Methods of a "belongs to" and "has many" relationships

Let's say that I have two tables in my database: users countries I have two defined relationships on each user belongsTo a country and each country hasMany users.. (CakePHP model relationships) And I want to crate the model findUsersFromCountry($countryID) in wich class/model this method will be? It must be inside the User model or t...

Inheritance mapping with JPA/Hibernate

This is a fairly lengthy (not overly complex) design question so please bear with me. I'm trying to implement a person/role management system with POJOs and JPA. I'm fairly new to ORM and this is mostly a mapping problem. I've got this working as POJOs and am comfortable with the caller-level API, but would now like to map it to a datab...

C# - Should an object be responsible for creating a history object when it changes something like status?

This is more of an architecture/best practices question than anything else, so please feel free to add your two cents. I know i stated status in the title, but this goes for any basic property of an object. I think the account example below will help demonstrate my question a little better than status. Here is a sample Account object: ...

How can I make sure an object has finished initialising before using it?

Writing some Objective-C in one method, I call +alloc, then -init to set up an object. object = [[MyClass alloc] init]; [object useFor:whatever]; The next few lines of code use the newly created object. If the aforementioned -init takes too long, I’m sure the program won’t “wait” before starting to use the new object, will it? If not...

Concatenate arrays of subclasses of the same superclass in MATLAB

I have the following structure in matlab superClass < handle subClassA < superClass subClassB < superClass say I have a vector A of subClassA and a vector B of subClassB. I would like to combine them like this: superVector = [A B]; but Matlab doesn't like this. What's the proper way to cast the subclass back to the superclass...

How do I use a setter instead of a constructor for a final variable?

I am parsing an XML file where one of the fields I want to be immutable, ID, has to be set after the object is created. Should I set it to null, and throw an exception in the setID() method if ID!=null ? Edit: I am parsing an XML file, and at the beginning, I create an object whose fields and objects are populated using information in X...