oop

Am I breaking the "Law of Demeter"?

I just recently became aware of the Law of Demeter. Like a lot of things, I realized that it was something that I was already doing but did not have a name for. There are a few places though that I seem to violate it. For example... I might have an Address object: public class Address : IAddress { public string StreetAddress { ge...

what is no-oo mvc in php?

what is no-oo mvc in php? If it is possible, give an example. If not, why? ...

how will Contained class call member function of containing class - Composition in C++

Hi, This is a general design question from C++ perspective. I have a container class which contains objects of 2 other classes. From container class we can call methods of the contained class object "as we have handle to the contained class object" e.g. objContainedClass1->SomeMthod(); But I want to know how would the contained class ...

Does javascript have the interface type (such as Java interface)?

I'm learning how to make OOP with javascript, and I wonder if it have the interface (such as Java interface) concept? So I would be able to create a listener... ...

how can i make this code by oop

i've a button called profile_btn i want to make this code by OOP profile_btn.addEventListener(MouseEvent.CLICK,profile_btnClickHandler); function profile_btnClickHandler(ev:MouseEvent):void { //The actual code to jump to a specific frame this.gotoAndPlay('play'); } another question how to include 3 classes to a specific fram...

Null Pointer Exception and scope in Java

I am trying to learn object oriented programming in the context of Java. I am writing a fairly simple code, but am getting this error: Exception in thread "main" java.lang.NullPointerException at Advisor_score.Rating.Score(Rating.java:12) at Advisor_score.Rating.main(Rating.java:25) Here is my code: package Advisor_score; public clas...

Problem with object oriented programming in Java

So I would like to start out by telling you that I am learning Java on my own and you guys are the nearest thing I have to teachers. So thank you so much for putting up with my simple and obvious question. I am just trying to learn. Once again I am getting an error that for the life of me I cannot figure out. Here is the error: Excepti...

Create new object within a for-in-loop

I want to create a new object and assign some properties for each array stored within some json. I have this mostly working except... for (var i in json) { a = 0; a++; a = new Object(); for (var key in json[i]) { var Key = key; var Value = json[i][key]; ...

Can't get JavaScript Array to work in OOP style

Hi currently I'm trying to get following snippet of code to work: function Entry() { var pauses = new Array(); } Entry.prototype = { AddElement: function(aParameter) { this.pauses.push(aParameter); } } Unfortunately this code fails with following error in Safari if I try to call AddElement("Test"); TypeError: Result ...

Get only declared methods of a class in PHP

Hello I need to get only the methods declared in a class, and not the inherited methods. I need this for cakePHP. I am getting all the controllers, loading them and retrieving the methods from those controllers. But not only are the declared methods coming, but also the inherited ones. Is there any method to get only declared methods. ...

OOP, protected vs public. When to use?

Im trying to understand the benefits of making a class variable private, versus public. I understand getters / setters to access / modify the private / protected data, but is its sole purpose is to 'keep me from mangling my data'? Example : I dont get how saying $person->age = x;//bad? has different potential for havoc than $person-...

Effect of refactoring on program speed

As a programmer I use to follow TDD, beginning by writing a simple version of my code then heavily refactoring it. When refactoring I usually just listen to my code. I search for bad smells and then refactor the code to remove smells. Typically I will introduce new methods to avoid repeating code, move class members around to put them ne...

PHP - OOP new class with agrument ?

class Dictionary { private $translations = array(); private $dictio; private $type; function __construct( $type, DictionaryIO $dictio ) { $this->type = $type; $this->dictio = $dictio; } // ... } $en = new Dictionary( "En", new DictionaryIO() ); $en->dictio = null; i saw something like above co...

error 1137: Incorrect number of arguments. Expected no more than 0

i found the error here what should i type in the constructor function between the braces to call the function to the main time line public function creation() { that's my code in the fla file //var createClass:creation = new Circle( this ); the constructor package { import flash.display.InteractiveObject; import flash.text.TextF...

Design issue: RMI needs explicit exporting of objects

I have two applications communicating via RMI, a slave server (of which there will be multiple) and a master server. Following good abstract design, I'd like to implement the slave in a way that it doesn't know that when talking to the master, it's using RMI (so that the two apps can also be run inside the same JVM, for instance): publ...

retrieving data from DB oop

I'm using the codeigniter framework, I'm retrieving data from the database in the form of an array but when i try to use the foreach function to display the data i get an error Message: Object of class stdClass could not be converted to string this is the array Array ( [0] => stdClass Object ( [id] => 1 [...

C# abstract method with base class only implementation?

Consider the following problem: You have a class 'A' that serves as a base class for a lot of other similar classes, eg. a class called B. The class A is useful in it self (and already used all over the place) and is hence not abstract. The crux is that you now wish to enforce a new protocol requiring all classes inheriting from A (in...

Class field resets to zero

im trying to make a simple game engine, it consists of 2 classes, Game class Game { protected: SDL_Event event; vector<Sprite> render_queue; void render(); public: int SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, FPS; SDL_Surface *screen; Game(int...

How granular do I get with my class design when trying to follow the SOLID principles?

I have an interface for Client Registration called IRegistrationService. This contains one method called Register and it is implemented through the class RegistrationService. If I wanted to have methods for Delete, Update, Retrieve for example, would I create a separate interface for each action such as IDeletionService, IUpdateService...

php OOP parent to child relationship

class base{ public $c = 'c'; public $sub = ''; function __construct(){ $this->sub = new sub(); } } class sub extends base{ public $ab = 'abs'; function __construct(){ $this->c = 'aas'; echo 'Test'; } } $a = new base(); print_r($a); I would like to the sub class to edit the base vars $this->c = 'blabla'; how can i ac...