oop

Special access to enclosing object?

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(...

Factory & Strategy patterns...

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...

Java: How can I require a method argument to implement multiple interfaces?

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...

Access to private Collection fields in Java

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)...

one method classes with enum in java

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...

Struts Actions and Composition over inheritance

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". ...

Implementation of OOPS in Oracle

Hi all, Can you give me some idea about implementation of OOPS in Oracle? Thanks in advance. ...

PHP Import Foreign Class' Method into MyClass

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...

Java, Get Class object for containing class, Not Runtime Class

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...

Why does this polymorphic C# code print what it does?

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"; } } ...

How do you use a custom framework with Objects in JQuery.

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...

C# Binding multiple textboxes to database

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 ...

What are some practical examples of abstract classes in java?

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? ...

NHibernate and Large Collections

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...

Threading from within a class with static and non-static methods

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() ...

Java, Call overridden method implicitly

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,...

How to use java interfaces with multiple implementing classes.

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...

Building a real object oriented framework in PHP, suggestions wanted

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 ...

Is it possible to write strictly typed PHP code?

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 } ...

How can you use ajax within an object to populate the object's instance variables?

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...