oop

load jquery dynamicly in a widget and enable noConflict mode

Hi. I am building a javascript widget and i plan to use JQuery so i need to load it dynamicly and set it to no conflict mode. I am using a Object Oriented approach in my js following the example of GetSatatisfaction.com widget (http://s3.amazonaws.com/getsatisfaction.com/javascripts/feedback-v2.js) I have also found this tutorial about ...

Keeping track of a class's references in PHP

I used the instructions in this post: http://stackoverflow.com/questions/475569/get-all-instances-of-a-class-in-php to keep all instances of a class in an array. But when I change an object inside of the array, it doesn't change the "original". class Pane { protected $data; public $name; public static $instances = array(); pu...

Access property with define()'d token?

I'd like to do this: <?php define('X', 'attribute_name'); // object $thing is created with member attribute_name echo $thing->X; ?> Attempting $thing->X, PHP takes X to be a property of $thing, and ignores the fact (rightly so) that it's a define()'d token. That in mind, I had expected $thing->{X} to work, but no dice. The only solu...

Using a hierarchy of classes, where subclasses have some unique features

Here's a design problem that I run into sometimes. Say I have a set of related classes, with some common features and some unique ones; interface TableCell { public function setContent($content); } interface HTMLTableCell extends TableCell { public function setID($id); public function setClass($class); } interface CSVTableCe...

Count number of times a PHP class is created.

I've got a php class that I create several instances for. I'd like to get a count of how many times I've created that object. <?php class myObject { //do stuff } $object1 = new myObject; $object2 = new myObject; $object3 = new myObject; ?> Is there a way to find that I've created 3 myObjects? ...

Passing Base Object Type When Using Inherited One

I have a project that has mainly two objects, both inheriting from a base. Like this: Public Class Vehicle Property Model As String Property Make As String End Class Public Class Truck Inherits Vehicle Property IsFlatbed As Boolean End Class Public Class Car Inherits Vehicle Property LeatherSeats As Boolean End...

Why are there no final interfaces in Java?

Extending an interface simply adds additional operations to be defined in any implementors and cannot break any existing implementations (unlike extending a class). But it can change (EDIT 3 WHICH CONSTANTS) and hence the PERCIEVED value of constants (EDIT 2 AS SEEN BY THE IMPLEMENTATION CLASSES). For instance, the following: interfac...

How JavaScript does OOP?

I am learning about creating objects in JavaScript. When I do this ... var Person = { name: "John Doe", sayHi: function() { alert("Hi"); } }; I know that I am creating an instance of a Person class, but I do not know how (or if) I can reuse that class to create another instance. What OOP features does JavaScript has? Does...

Trying to figure out the hierarchy of classes in my XNA game...

I am still kinda new to developing games in XNA and using classes with C#, but I want to start a semi-decent game project where I can learn without throwaway projects. I want to devide my game up into classes. For example a main game class, a player class (i want two players, and they battle against each other), a level class (for drawi...

Why is PHP considered Object Oriented?

I have been reading around the definition of OOP and couldn´t get why PHP is considered object oriented. Can this have anything to do that the "basic level" of PHP isn´t and more advanced features are? Thanks in advance! ...

How do I create a JavaScript Object with defined variables and functions?

Let's say I want to create an Object called 'Vertex'. Usually, in Java I would do this by: public class Vertex { // member variables public data; private id; // member methods public Vertex() { /* default constructor */ } public getID() { return id; } } Now, how would I do that in JavaScript? I want to preserve pri...

php how to get __DIR__ of child class

I have two classes in separate folders class Parent { public $path = null; function __construct() { $this->path = __DIR__; } } and class Child extends Parent { } So when I create an instance of Child: $child = new Child(); echo $child->path I get a path to Parent. What I actually want is to get path to...

PHP OOP Function Precedence

Just a quick one. In OOP PHP, if I have a function defined in the parent class, and a modified version in the child class, and I call it from an instantiated object of the child class, will it use the child class's version of the function? I am pretty sure it will just double checking, as there is no way for me to check within the runni...

Public variable not accessible in my classes

I am using the XNA framework to make one of my first games. In it's main game class (Breakout.cs), I put this: public int screenHeight; public int screenWidth; And in the Initialize method: this.screenHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height; this.screenWidth = GraphicsAdapter.DefaultAdapter.CurrentDisplayMod...

Variable value assignment operation duplication

Context From The Pragmatic Programmer: Every piece of knowledge must have a single, unambiguous, authoritative representation within a system. Questions How is that statement reconciled with directly setting a private member variable's value throughout a class in multiple places? Does it matter as there can be no external de...

Looping over object values works as intended, but first value is undefined?

Hi there! Could someone explain to me why objectInfo method on the third button returns undefined for the first value? http://jsfiddle.net/PnSSX/11/ I can't figure out where this comes from, because there is no property before name... Can you help? Am I missing something? Best regards, shapeshifta ...

PHP Callback function not working on object functions

I have an array and want to apply MySQLi->real_escape_string on every member of the array through array_walk but this is not working: array_walk($array, '$mysqli->real_escape_string'); It gives this error: Warning: array_walk() expects parameter 2 to be a valid callback, function '$mysqli->real_escape_string' not found or invalid ...

OOPHP - How do I create multiple objects from an array of database rows?

I'm new to "Object Oriented" PHP, but have managed to figure most things out so far. I'm building a website where users can register an account and then add, let's say, hobbies onto their profile. I've managed to figure out creating the class, object, storing a single user in the database, and retrieving a single user from the database ...

How do I allow a class to construct other classes when those other classes are passed in by the user?

Say you have a class Population and Population makes an internal List of Individuals. The user wants to pass an unconstructed Individual subclass to Population and let Population do the work of constructing these, whatever subclass was passed. public class Population{ private List<Individual> indiList = new ArrayList(25); /...

Real world abstract class usage simple samples

Hello, Any real world simple samples of using abstract class? I'm trying to get in PHP's OOP, but I still can't understand - why abstract class should be used and when (Yes, I know that it's impossible to create abstract class instance, only instance of class inheriting it). Thank you ...