In the middle of a period of big refactorings at work, I wish to introduce stdClass * as a way to return data from functions and I'm trying to find non-subjectives arguments to support my decision.
Are there any situations when would it be best to use one instead of the other ??
What benefits would I get to use stdClass instead of arra...
I understand the principles of Coding to Interfaces - to decouple the implementation from the interface, and to allow implementations of the interface to be swapped in and out.
Should I code to interfaces for every class I write or is that overkill? I don't want to double the number of source files in a project unless it's really worth...
Hi to all,
I have a question, I have a base class and an another class which derived from the base class. Can we access derived class in the base class.
Thanks in advance
...
I am trying to add new methods to an object dynamicaly.
Following code works just fine:
use SomeClass;
my $obj = SomeClass.new;
my $blah = 'ping';
my $coderef = method { say 'pong'; }
$obj.^add_method($blah, $coderef);
$obj.ping;
this prints "pong" as expected, whereas the following will not work as expected:
use SomeClass;
my $...
hi there,
I am working on my first module for magento version 1.3.2.3.
I have created a simple table (not EAV, just a primary key and 2 columns) and some classes to access it, following Alan Storm's articles which helped me a lot, but I can't figure out how to make a simple select: Alan explains how to load with the primary key, but not ...
I have a class that looks like:
class Foo
{
public:
Foo();
virtual ~Foo();
private:
Odp* bar;
};
I wish to initialize bar to NULL. Is this the best way to do it?
Foo::Foo() : bar(NULL)
{
}
Also, is it necessary that the destructor is virtual? (If that is true, then must the constructor be virtual as well?)
...
I have several applications that need to read and write application settings. Since one of the apps is a legacy c++ app with hundreds of settings in the registry (and that isn't bound to change) and there are also some settings stored in a proprietary database format I'm wondering how the architecture could be setup to allow a single in...
Hey guys, so I'm completely new to Object Oriented PHP -- I've read some tutorials, but I can't find anything that really goes into working with a database with PHP classes.
I'm trying to make something simple -- a quick news post class. You get the post from the database, etc. However, I'm getting an error whenever I try to interact wi...
Is it possible to implement friend function and friend class (as in c++) in F#?
Update:
Since there is no friend function/class in f#, and friend is not even a reserved keyword for future expansion, I'm wondering is there any problems with the friend mechanism in F# that make the developers to decide not to implement it?
(such as in "p...
This is a kind of open question. I always keep scratching my head when deciding between these. I can pass values to a class by:
Passing an argument to class function:
MyClass m = new MyClass();
m.DoSomething(arg);
Passing argument when creating object:
MyClass m = new MyClass(arg);
m.DoSomething();
Setting the value using a differ...
I cannot seem to google this one correctly... I have a class (Widget) that represents a database table from the Data Layer.
The table holds 3 different types of records, where one uses only 5 columns, another uses 10 columns etc. Each record has a different set of validation and business rules that I want to control with Business Layer ...
I tend to have a class to describe a general concept and subclasses to describe variances in that concept. For example, Polygon <|-- {Rectangle, Triangle, etc.}.
However, I often find I have various representations of these hierarchies. For example, I want to keep the graphical representation (eg, a QPolygon), or the physical represen...
Looking to see if there is any way to implement the kind of functionality of the __get() magic method, but when trying to instantiate a new class.
My goal is to have
$foo = new Cat();
Ultimately result in the creation of a generic object, i.e.
new Mammal('Cat');
Such that $foo would be an instance of the class Mammal, with the calle...
I am calling a constructor in ClassA and want to have the resulting object be of a different class (ClassB) if a certain condition is met. I've tried replacing the first argument to __init__() ('self' in the example below) within __init__() but it doesn't seem to do what I want.
in main:
import ClassA
my_obj = ClassA.ClassA(500)
# un...
I thought all function and method arguments in Python were passed by reference, leading me to believe that the following code would work:
class Insect:
def status(self):
print "i am a %s" % self
class Caterpillar(Insect):
def grow_up(self):
self = Butterfly() # replace myself with a new object
...
In designing class with multiple/nested has-a relationships, who should catch exceptions?
I guess this depends on design but is there any rule of thumb?
...
By lower level package I mean a package a.b.c.d and by higher level package I mean a.b.c and I've used the terms in relation to each other. I'm not sure if there's a terminology for defining such levels.
However, from object oriented perspective, I wanted to know if it is a good idea to call a.b.c.d.aClass.aMethod() from a.b.c.anotherCla...
I'm writing my code in haXe. This is quite irrelevant to the question though, as long as you keep in mind that it's a high level language and compareable with Java, ActionScript, JavaScript, C#, etc. (I'm using pseudocode here).
I'm going to work on a big project and am busy preparing now. For this question I'll create a small scenario ...
I have a vb.net application which runs as a service. I also have another Windows application that serves as the service interface.
In brief the service watches some folders for new files and imports them into various databases. In the service I have an class called 'importFile' containing basic properties such as 'FileName' and 'ImportS...
Is it possible to create a new Location object in javascript? I have a url as a string and I would like to leverage what javascript already provides to gain access to the different parts of it.
Here's an example of what I'm talking about (I know this doesn't work):
var url = new window.location("http://www.example.com/some/path?name=va...