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...
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...
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...
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...
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...
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...
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...
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...
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...
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...
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...
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 {}...
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...
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...
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....
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) {...
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...
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...
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...
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);...