Is there a way, in PHP5.3, for an object $enclosed to know which object $enclosing that it is inside of? Essentially I want to make some variables of $enclosing be accessible only to $enclosed without specifically passing those vars in.
class Enclosing {
private $enclosed;//Enclosed object
private $othervar;
function __construct(...
I need to create a class which will be responsible for result set processing but it might happen that different algorithms should be used to process that result set.
I am aware of the following options:
1) Use Strategy patern, below is pseudo code:
interface Strategy {
processResultSet(ResultSet rs);
}
class StrategyA implements St...
It's legal to do this in Java:
void spew(Appendable x)
{
x.append("Bleah!\n");
}
How can I do this (syntax not legal):
void spew(Appendable & Closeable x)
{
x.append("Bleah!\n");
if (timeToClose())
x.close();
}
I would like if possible to force callers to use objects that are both Appendable and Closea...
One of my classes has a field which contains a Set. This field is only ever filled in the constructor, and then read by other classes. Originally I had something like this:
public class Foo {
public final Set<String> myItems;
public Foo(Collection<String> theirItems) {
this.myItems = new LinkedHashSet<String>(theirItems)...
I have an enum that looks like
public enum MyEnum
{
myValue
{
@Override
public String myMethod(String dostuff)
{
return dostuff + "One";
}
},
myOtherValue
{
@Override
public String myMethod(String dostuff)
{
return dostuff + "Two";
}
},
aThirdValue
{
@Override
public St...
When I want to apply the DRY principle, i.e. to unify the code of multiple Struts action for different use-cases (for example the administrator role and the operator role ), one option would be to use an abstract base class "BaseAction" for the action and then use "AdminAction extends BaseAction" and "OperatorAction extends BaseAction". ...
Hi all,
Can you give me some idea about implementation of OOPS in Oracle?
Thanks in advance.
...
Wondering if this is possible in PHP Land:
Let's say I have a class as follows:
class myClass{
var $myVar;
...
myMethod(){
$this->myVar = 10;
}
}
and another class:
class anotherClass {
...
addFive(){
$this->myVar += 5;
}
}
The 'anotherClass' is 3500 lines long and I just want the single 'addFive' m...
Consider this Java code
class A{
//@returns Class object this method is contained in
// should be A in this case
public Class<?> f() {
return getClass();
}
}
class B extends A {}
B b = new B();
System.out.println(b.f());
//output -- B.class (Wrong, should be A.class)
inside f() i can't use getClass() because that will give m...
I was recently given the following piece of code as a sort-of puzzle to help understand Polymorphism and Inheritance in OOP - C#.
// No compiling!
public class A
{
public virtual string GetName()
{
return "A";
}
}
public class B:A
{
public override string GetName()
{
return "B";
}
}
...
Hi,
I have just started a new job out of uni and I am learn OO PHP we have a custom framework where I work and my boss was talking about teaching me how to use JQuery with objects. I am also unsure whether he means objects from PHP classes or whether JQuery has its own object of some type. I am not sure exactly what he means by this. I...
I'm trying to Bind 3 textboxes to a Class that retrieves any previously stored records for each of the 3 textboxes. I don't know how to retrieve 3 different values from a class in a Object Orientated perspective. I know how to return single strings, bool, etc vars but not more than 1 at a time.
example of a simple bool returning method ...
When and why should abstract classes be used? I would like to see some practical examples of their uses. Also, what is the difference between abstract classes and interfaces?
...
As a way to learn NHibernate, I came up with a small project that includes a typical users & groups authentication system. It got me thinking about how this would be done. I quickly put together the following classes and mapped them to the database, which worked after a lot of trial and error. I ended up with a three-table database sc...
Let's say I have
class classA {
void someMethod()
{
Thread a = new Thread(threadMethod);
Thread b = new Thread(threadMethod);
a.Start();
b.Start();
a.Join();
b.Join();
}
void threadMethod()
{
int a = 0;
a++;
Console.Writeline(a);
}
}
class classB {
void someMethod()
...
Right now in some Java code I have something like this
class A {
void f() {
}
A() {
f();
}
}
class B extends A{
@Override
void f() {
//do some stuff
super.f();
}
}
class C extends B {
@Override
void f() {
//do some stuff
super.f();
}
}
I want to have f() called and then iterate upwards through each parent class,...
public interface Foo {
}
public class SpecificFoo implements Foo {
}
public interface SomeInterface {
void thisMethod(Foo someKindOfFoo);
}
public class SomeClass implements SomeInterface {
public void thisMethod(Foo someKindOfFoo) {
// calling code goes into this function
System.out.println("Dont go here please");
}
public...
I've been using the CodeIgniter framework, however after learning Java and awesome features like Interfaces, Abstract classes, packages, and that PHP 5 also supports most of these features, I'm ready to graduate and build a real OO framework in PHP which uses all of these features (including namespaces), so I can build much more elegant ...
For example, is it possible to write code like this:
int $x = 6;
str $y = "hello world";
bool $z = false;
MyObject $foo = new MyObject();
And is it possible to define functions like this:
public int function getBalance()
{
return 555; //Or any numeric value
}
...
I have multiple objects in a hierarchy which have common properties and methods inherited from the superclass, and object-specific properties and methods in the subclasses. I'm still new to OOP javascript, so there is probably a much better approach to this. I'm using jQuery for the AJAX, but not sure if that makes any difference.
fun...