Let's say I have a method that takes a class, which is called like so:
[registry registerClass:[MyClass class]];
How do I interrogate the class inside -registerClass:?
-(void) registerClass:(Class)typeClass {
// Verify that instances of typeClass confirm to protocol / respondsToSelector
// ?
// Do stuff
// ...
...
I have an abstract base class in my application.
I want to provide an factory() method to allow me to make a new model easily with a static method.
public static function factory() {
$class = __CLASS__;
return new $class;
}
This obviously doesn't work as it tries to initiate the abstract class.
What I wanted to know,...
Even though I've been programming for quite a while now, when it comes to coupling objects I always seem to bang my head against the wall so I'm wondering if anyone has any resources or golden rules I can follow.
Let me give a small example, in no particular language...
class Person {
private int personnel_id
private String fir...
hi there
im am making a php validation class
with sub classes that extend it, eg, mobile, suburb, credit_card, ect
so, the idea is you can call
$validation = new Validation('mobile');
$valid = $validation->validate($number);
$validation->type('suburb');
$valid2 = $validation->validate($suburb);
now my idea for doing this is having
...
$laca = 'laca';
class laca(){ /*Code*/ }
class foo extends $laca;
This code doesn't work.
I want to make a DB class, and then have some DB driver : mysql, mssql v..v.
$db = 'mysql'; So I want the DB class to extend mysql.
Sorry for my bad English.
...
-------Now, another question
class DBFactory {
static function create(){
return new MysqlDB();
}
}
class MysqlDB{
function alo(){
echo 'ok';
}
}
$db = DBFactory::create();
$db->alo();
--->Works
class DBFactory {
function create(...
Can abstract class's Constructor be marked as 'abstract'?
...
Hello. Is it possible to set the parent of the class? I.e. an instance of the parent class gets instantiated during runtime and then a child class instance extending a certain parent instance gets created. For example:
class A {
var $test = 'default';
}
class B extends A {
public function __contsruct(A $a) {
parent = $a...
<?php
class DBFactory {
function __construct(){
return 'Need to echo';
}
}
$db = new DBFactory;
echo $db;
?>
Not works :(
...
A.as :
public class A {
public function getFunction():Function {
return function():void {
if(this is C) {
trace("C");
} else {
trace("not C");
}
}
}
public function func1():void {
var internalFunc:Function = getFunction();
internalFunc();
}
}
B.as :
public c...
I have a problem in a VB.Net class library which I have simplified greatly down to the following...
Public MustInherit Class TargetBase
End Class
Public Class TargetOne
Inherits TargetBase
End Class
Public Class TargetTwo
Inherits TargetBase
End Class
Public Class TargetManager
Public Sub UpdateTargets(ByVal Targets As L...
Was not exactly sure how to phrase this question or what to search on so if this is the same as another question please close and redirect to the appropriate question.
Suppose
template<typename Type, int Size> class vector
{
Type data[Size];
}
Is it possible to replace a constructor which takes Size number of arguments in template ...
Even though OOP uses objects and data encapsulation, the code still writes out like a procedure. So what makes OOP loose the procedural label? Is it just because it is considered "high-level"?
Thank You.
...
Hi Everyone,
I've created a generic 'SocketServer' class in java which takes the following arguments:
String address, int port, Class socketProtocol, String encryptionType, int backlogSize
Basically, I want other developers to be able to instance this class in their projects and set some simple options for encryption, backlog, address,...
I am using php 5.3, and yes, there is a bug open for that, but some think this is not a bug, and this makes me wonder.
abstract class A{
private function bobo(array $in){
//do something
}
}
class B extends A{
private function bobo($shmoo,$shmaa){
//do something
}
}
This throws an error. Shouldn't inheritance ...
I've noticed that some programmers like to make interfaces for just about all their classes. I like interfaces for certain things (such as checking if an object supports a certain behavior and then having an interface for that behavior) but overuse of interfaces can sometimes bloat the code. When I declare methods or properties as public...
In C# I can declare the following
class A {
int Field;
}
class B : A {
int Field2;
}
static int f(A a) { return a.Field; }
static int f(B b) { return a.Field + b.Field2; }
static void Main(string[] args) {
A a = new A() { Field = 1 };
A b = new B() { Field = 1, Field = 2};
Console.WriteLine(f(a) + f(b));
}
In H...
Is it possible for a PHP object instance to destroy/unset itself? Say I had a class that represented a file, and then I subsequently delete that file using the class. Can I somehow unset the instance from within one of its own methods?
$file = new FileClass();
$file->copy('/some/new/path/');
$file->delete();
// ... at this point $file...
Hi all,
I'm about to begin work on my first ever PHP project -- building a new website for a small non-profit organization. Coming from a .Net and Java background, object oriented programming comes very naturally for me, but I'm not sure if it's the right approach for bulding a website of moderate complexity in PHP. My understanding is ...
Hello everybody
In below example, i defined number field. This field will work as i wanted but it is not enough efficient to provide my expectations.
number value is fixed value for each class,number is not dependent instances and number support polymorphism. How can i do that ? Or is there another solution for not use unneccesary numb...