oop

Can we create a class from a xml file ?

Hello, Is it possible to create a class dynamically by reading an xml file ( in java preferably) ? if yes, please provide pointers on how to do it. In the process of development, we have come up with a class that has 5 attributes, all these attributes correspond to an entry in the xml file, now if the user adds/modifies the xml entry...

php destructor behaviour question

Hello, im trying to understand php constructor and destructor behaviour. Everything goes as expected with the constructor but i am having trouble getting the destructor to fire implicitly. Ive done all the reading on php.net and related sites, but i cant find an answer to this question. If i have a simple class, something like: class ...

Use string value to create new instance

I have a few classes: SomeClass1, SomeClass2. How can I create a new instance of one of these classes by using the class name from a string? Normally, I would do: var someClass1 = new SomeClass1(); How can I create this instance from the following: var className = "SomeClass1"; I am assuming I should use Type.GetType() or someth...

What are pointers to class members used for?

I have read about pointers to class members, but I have never seen them being used in any practical applications. Can someone explain what are the use cases of such pointers? Is it really necessary to have such pointers? Eg. class abc { public: int a; abc(int val) { a = val; } }; int main() { int abc::*data; abc obj(5)...

Getting the variable name of an instantiated class in PHP

Hi, Is it possible to get the variable name used to reference an instantiated class from within the class? here's an example of what i mean: class Test { function getName(){ //some code here to get the name '$test1' in this example } } $test1 = new Test It's not a must for this to be possible, but it'd help for a project ...

C#: is there way for a class to 'remove' methods that it has inherited

Is there way for a class to 'remove' methods that it has inherited? eg. If I don't want my class to have a ToString() method can I do something so that it is no longer available? ...

Is it true that in most Object Oriented Programming Languages, an "i" in an instance method always refers first to local, and then to global, but never to the instance variable or class variable?

In the following code: <script type="text/javascript"> var i = 10; function Circle(radius) { this.r = radius; this.i = radius; } Circle.i = 123; Circle.prototype.area = function() { alert(i); } var c = new Circle(1); var a = c.area(); </script>...

Implementing N-tier structure in .net

Hi friends, my requirement - suppose I have three classes namely Employee, Customer and Department. Employee contains attributes id, name, dept. Customer contains id and name. Department contains id and name. Now all three class have common functionality i.e. create, update and delete. I want to implement these functions using an interfa...

Many-to-many relationship in oop

what is best way to model many-to-many relationship? lets say we have a two classes , Team and Player any given Player can be in multiple Team s any Team can have as many Player s as they like I like to call methods like playerX.getTeamList() to get the list of all the Team s he/she is in teamY.getPlayerList() to get the list of ...

strategy for observer pattern?

I want to use observer pattern for a logging system. We have got logObservers and logObservables. The class that will have to log something will implement iLogObservable and include these methods: private $logObservers = array(); public function addLogObserver($logObserver) { $this->logObservers[] = $logObserver; } public functio...

class composition instead of object composition?

I want a class property to be reference to another class, not its object and then use this property to call the class's static methods. class Database { private static $log; public static function addLog($LogClass) { self::$log = $LogClass; } public static function log() { self::$log::write(); // seems ...

where are the frameworks for creating libraries?

Whenever I create a PHP library (not a framework) I tend to reinvent everything every time. "Where to put configuration options?" "Which design pattern to use here?" "How should all the classes extend each other?" and so on... Then I think, isn't there a good library framework to use anywhere? It's like a framework for a web applic...

Need help extrapolating Java code

If anyone familiar with Rebecca Wirfs-Brock, she has a piece of Java code found in her book titled, Object Design: Roles, Responsibilities, and Collaborations. Here is the quote >Applying Double Dispatch to a Specific Problem To implement the game Rock, Paper, Scissors we need to write code that determines whether one object “beats” ano...

Class model for a many-to-many relationship, where relationship has attributes

Hi, What would the basic C# code look like to model a many-to-many relationship, where the relationship itself has attributes? And also in this case the many-to-many was referential. So a possible database model for this might look like the following (just to give an example of what I'm talking about) Nodes ID Name Description Rel...

What is faster: write PHP code using "functions" or writing it as pure script?

What is faster: writing PHP code using functions or writing it as pure script? So, as I see it Apache or any other server will create from PHP code using functions a pure script... I mean we had: function foo($a, $b){ return ($a + $b); } echo foo(4, 5); and PHP will turn it into something like: echo 9; Or will it? ...

How can I create a list of classes in C# to iterate over in a loop

Suppose I have class animal and classes cat and dog extending it. I want to do something along the lines of: foreach (class a in {cat, dog}) if (a.isValid(parameters)) doStuff(); isValid is a static method from animal that just checks if the given parameters define an object of the given type doStuff means I'm doing stuf...

Setting javascript prototype function within object class declaration

Normally, I've seen prototype functions declared outside the class definition, like this: function Container(param) { this.member = param; } Container.prototype.stamp = function (string) { return this.member + string; } var container1 = new Container('A'); alert(container1.member); alert(container1.stamp('X')); This code prod...

filename for class files: file.class.php or file.php?

i have seen a lot of coders choosing this filename convention: file.class.php. is this a standard of naming class files? just curious. so i know if i should follow it for all class files in the future. thanks ...

how to call another classes method from within a class?

here is my setup. class testA { function doSomething() { return something; } } $classA = new testA(); class testB { $classA->doSomething(); } this wont work inside that class.: $classA->doSomething(); how else would i do it? ...

do you call them functions, procedures or methods?

consider a standard c# 'function' public void foo() { //some code } In c or c++ this is called a 'function' - even if taking no parameters and returning no value. In another language maybe it would be a 'procedure'. In object orientation speak it would be called a 'method' if a class member. What would be the correct term to use in c#?...