oop

What happens on this my declaration? [ Perl ]

I know the title sounds funny, but I found this snippet somewhere: my MyPackage $p1 = MyPackage->new; What role does the name of the package serve in front of $p1? EDIT: I'm running perl 5.10.1. ...

Dynamically Auto-Linking instance variables to object functions in javascript / jquery?

Hey all, I'm trying to create a robust audio player in javascript (& jQuery). I know that there are other players out there, but I'd like to try creating my own (so please don't refer me to jquery plugins). This is essentially what I would like to do: Main.js: var player = new Player(AudioObj); // Audio object links to Audio class (n...

Is it bad practice to have a class that requires a reference to the instantiating object?

I saw this in someone's code and thought wow, that's an elegant way to solve this particular problem, but it probably violates good OO principles in an epic way. In the constructor for a set of classes that are all derived from a common base class, he requires a reference to the instancing class to be passed. For example, Foo Foo_i...

Abstract keyword in PHP

Hey, I'm quite experienced with PHP but I have no idea what the keyword abstract does when it comes down to object orientated programming. Can anyone explain in plain english what it can be used for? What situations would I use the abstract keyword in? How does it change the class/interface? ...

OOP: trouble notifying other objects in hierarchy

Hi, I always struggle with sending messages between objects. Consider the hierarchy of objects of a quiz: Quiz QuestionList Question AnswerList Answer So: a Quiz has a QuestionList a QuestionList has multiple Questions a Question has an AnswerList a AnswerList has multiple Answers When an Answer gets clicked (we're talkin...

PHP MVC Framework Design

Hi there, I currently ran into a problem I can not really solve by myself: I ve started to code a "small" framework (browsergame-framework), which follows the MVC pattern in some way. Now I have my index, bootstrap, db adapter, dispatcher, wrapper, but I do not really know "how" to link them. I coded their methods etc. but I do not kn...

How to implement class composition in C++?

If I understand correctly we have at least 2 different ways of implementing composition. (Implementation with smart pointers is excluded case for simplicity. I don't use STL almost and have no desire to learn it.) Let's have a look at Wikipedia example: class Car { private: Carburetor* itsCarb; public: Car() {itsCarb=new...

When to use a property vs a method?

Possible Duplicate: Properties vs Methods Is there any rule or general best practice as to when to use a property vs a method? Technically any parameterless method can be made in a property and any property can be made a method, but sometimes when to decide when to use one of the other can be blurred. I was hoping to get some r...

Why Aren't the _construct() Methods on EAV Resources and Collections Declared as Abstract Methods?

I've been poking around the bowels of Magento systems code. For "regular" model resources, Magento's _construct initialization convention has been declared abstract File: Mage/Core/Model/Resource/Abstract.php abstract protected function _construct(); This makes sense, as it forces developers creating their own Model resources to call...

$this variable in PHP

Hello all, I've just started getting familiarized with OO features of PHP, and I would like to ask you something about the $this variable. First of all, if a class that I'm using the $this keyword in does not have a defined property variable foo, does that mean that using the following code: $this->foo = 5; echo $this->foo; will crea...

Nesting objects and where to retrieve data?

Hi all I am trying to re-write an existing system with objects. I have created a few basic objects but am stuck on exactly how to get them to work how I want. These are the basic classes: Public Class Course Public AcadPeriod As String Public AoSCode As String Public AoSPeriod As String Public Title As String Publ...

Call class method from variable in Python

Hello there! If I have a Python class, and would like to call a function from it depending on a variable, how would I do so? I imagined following could do it: class CallMe: # Class def App(): # Method one ... def Foo(): # Method two ... variable = "App" # Method to call CallMe.variable() # Calling App() But it...

OO design and mirrored/duplicated methods

Hi everyone! I'm having an issue in OO design where I end up with duplicate code in 2 different classes. Here's what's going on: In this example, I want to detect collision between game objects. I have a base CollisionObject that holds common methods (such as checkForCollisionWith) and CollisionObjectBox, CollisionObjectCircle, Collis...

oracl + OOP and types

HI ALL: I am trying to make an object oriented data base and I have the types : client is the base object(class) player is under it and captain is under player and i need a a table to store data how can i make a table of client so i can store all these types in it and who can i insert into it and select please give example if you can tha...

Why does jQuery use "new jQuery.fn.init()" for creating jQuery object but I can't?

I try to create some class based-on jQuery style like the following code. myClass = window.myClass = function(x, y) { return new myClass.fn.init(x, y); }; myClass.fn = myClass.prototype = { init: function(x, y) { // logic for creating new myClass object. } }; I do not understand why jQuery use new keyword for...

PHP: How to instantiate a class with arguments from within another class

Hello All, I am in a situations where i need to instantiate a class with arguments from within an instance of another class. Here is the prototype: //test.php class test { function __construct($a, $b, $c) { echo $a . '<br />'; echo $b . '<br />'; echo $c . '<br />'; } } Now, i need to instantiate above class using below cla...

How to call a method in class from its replaced implementation?

Hai, I am trying to understand few concepts in JavaScript. Consider the following code: function Person(name, age) { this.name = name || "no name"; this.age = age || "age not specified"; this.printStr = function() { console.log("< " + this.name + ", " + this.age + " >"); }; } p = new Person("pranav", 26); p...

Moose ArrayRef attribute returned as an Array

I have a Moose class with an attribute that is an ArrayRef (read-only) and is manipulated internally by the object. But when someone calls the accessor method I want it to return an Array (or list) not a reference. Not only would this cut down on the amount of dereferencing that the user of the class has to do, but it will mean they can'...

What language to use to kickstart my learning into OOP?

So I am a hardware engineer turned software engineer due to recent job duties. I have a very strong understanding of procedural programming (mainly in 'C' and 'bash' scripting) but I only have a passing knowledge of what OOP is. I look around and just about every modern language has very firm roots in OOP (C++, java, python, ruby etc.)...

Philosophical Design Questions for OOP-Tetris

You are writing a Tetris program in Java. How would you set up your class design with regards to the following aspects? Piece class: Have one Piece class, with an internal array which determines the shape of the piece, versus having seven Piece classes, one for each of the pieces. They are all subclasses of one generic Piece class. Pie...