oop

In which class would you put these methods?

If I have a User class, and his account can be suspended by adding an entry to the suspensions table, which of these class/method signatures do you think is more appropriate? User::suspend($reason, $expiryDate); Suspension::add($userid, $reason, $expiryDate); This is a simple example, but I have this kind of situation everywhere throu...

Javascript Member Functions Out of Scope

I have a class that creates an anchor object. When the user clicks on the anchor I want it to run a function from the parent class. function n() { var make = function() { ... var a = document.createElement('a'); a.innerHTML = 'Add'; //this next line does not work, it returns the error: //"this.add_but...

How to copy an object by value / clone an object in PHP 5

I have this code: foreach ($this->configObjects as $k=>$object) { $configObject=$object; //Here I will make a lot of changes to $configObject, however // I want all those changes to be kept only to the local copy of $configObject, // So the next time this foreach loop is run $this->configObjects array will contain // a c...

How does inheriting from NSObject work?

There are a couple of things about Objective-C that are confusing to me: Firstly, in the objective-c guide, it is very clear that each class needs to call the init method of its subclass. It's a little bit unclear about whether or not a class that inherits directly from NSObject needs to call its init method. Is this the case? And if...

Admin Log-In Development

I am developing the ability for administrators to log in and I'm to the point of creating the admin log-in page, but I'm somewhat torn as to where the best place to put it. For details, this is part of an MVC framework, and the administration portion is in it's own folder - /admin; so administration is completely separate from the publi...

Use method flag or new method?

If I have a method that does something and additionally logs information, should I create a new method if I don't want to log or use a flag? public void MethodA(string myMessage, bool logIt) { if(logIt) { //do stuff with logging } { //don't need to log } } ...vs... public void MethodA(string myMessage) { //do stuf...

C++ game, class design and responsibilities

I've just read some related questions that came up when I typed the subject, so I'll try not to repeat those. I've recently started revisiting a learning project I started about two or three years ago - a C++ port of a Mega Man engine. Yes I used ripped sprites. I also am using a game engine library for drawing, music, and input. My or...

State vs. Behavior

Sometimes objects consist of pure data. Such objects have fields, accessors, and virtually no other methods. Sometimes objects consist of pure behavior. They have other objects representing their state, or data is passed as method parameters. Usually such objects represent algorithms or some kind of policies. What state/behavior ratio...

History of public/private/protected

How did these keywords and concepts come to life? What were the forces and problems that made them appear? What was the first language to have them? Actually, it's not just about public/private/protected, but rather the whole range of keywords that enforce some rules (abstract, final, internal). But, please, do not assume things. Answe...

Extending the Sprite class for convenience?

I'm always tempted to extend the Sprite class just so my object can be part of the display list (and also have EventDispatcher functions), even though it has nothing to display. It will, however, contain things to be displayed. It's convenient because those contained objects need only reference their container for display list access. H...

how to extract object .net

I have a function that returns this object: var result = AjaxUserToPlacePaging(); //this is the object object[] objcs = new object[1]; objcs[0] = new { countHereNow = countHereNow.ToString(), countWillBeHere = countWillBeHere.ToString(), countWasHere = countWasHere.ToString() }; How can I extract the information...

OOP - overloading a child and its parent class in the same time?

Hi, I'm working with a framework, but for sometimes I need to alter some methods by overloading classes. My problem is when a class B inherits from a class A and where I need to overload them both, eg: class B extends A {} First I overload A and B, in order to alter some of their methods: class AA extends A {} class BB extends B {}...

Creating classes or just using associative arrays for XML data in PHP?

From a maintenance and code organization standpoint, in PHP5, does it make sense to create/define objects and classes for XML data coming from a web service? Using Twitter's API as an example, I would have a class for each API method (statuses, users, direct_messages, etc). For statuses/public_timeline, I would have something like this...

How to document a Class and shows its constructor params when instantiating, using Netbeans autocomplete?

I'm documenting the company framework for use with our default IDE (Netbeans). It's normal that we send as params a new Object, like here: $this->addControl(new TextControl('name', 'value')); I could document the __construct() params at the normal place, but they aren't showed when you do a new <ctrl+space>. So I tried to move this d...

avoiding if statements

I was thinking about object oriented design today, and I was wondering if you should avoid if statements. My thought is that in any case where you require an if statement you can simply create two objects that implement the same method. The two method implementations would simply be the two possible branches of the original if statement....

How to use a class's method inside a function (PHP) ?

I'm trying to use the new PHP mysqli extension. I've got a function (safe()) that recursively uses mysql_real_escape_string to make strings safe. How do I use my mysqli connection inside this function to call the mysqli::escape_string() function? Example: $db = new mysqli($host,$user,$password,$database_name); function safe ($data) {...

n-tier design - best way to pass data retrieving object

I'm using a basic 3-tier design. For flexibility (and testing) purposes, I wanted the data layer to be abstract and specify the concrete class in my code. But, how should I pass this along to my business objects. Here's an example (pseudo code): abstract class IDataLayer { PersonData GetPerson(int); //PersonData would be a row of da...

When to Subclass instead of differentiating the behaviour

I'm having difficulties deciding when I should be subclassing instead of just adding an instance variable that represents different modes of the class and then let the methods of the class act according to the selected mode. For example, say I've a base car class. In my program I'll deal with three different types of cars. Race cars, bu...

addEventListener "this"

I've created a javascript object via prototyping. I'm trying to render a table dynamically. While the rendering part is simple and works fine, I also need to handle certain client side events for the dynamically rendered table. That, also is easy. Where I'm having issues is with the "this" reference inside of the function that handle...

How should i set up my classes?

I'm starting to work with oop to build a site of user generated data. There are different types of data coming from my classes. I have functions that get a list of data from the database, and functions to just select one item from those lists. For example function Get_Article($aid); //Gets an article function Get_Users_Articles($uid);...