Skip to main content

alphaWorks  >  Forums  >  Hyperj  >  developerWorks

Is it possible to override Constructors?    Point your RSS reader here for a feed of the latest messages in this thread


     

 
 

My developerWorks
 Welcome, Guest
Sign in or register
Permlink Replies: 0 - Pages: 1 Threads: [ Previous | Next ]
Ouafa
Is it possible to override Constructors?
Posted: Nov 10, 2004 09:34:12 AM
Click to report abuse...   Click to reply to this thread Reply
Hello,

Im using Hyper/J to propose new aspect-oriented implementations for the GoF Object-oriented design patterns.

I noticed that every time I try to define a new constructor for a specific class -with the same signature- in order to compose it with the original class's constructor, the override general strategy (or the Override relationship) will not produce a composed constructor which only invokes the newly defined constructor. Although, in reality, the composed operation results on a merge integration of the two constructors- in the sense described for mergeByName or merge relationships- even the composition rule is override.

Furthermore, even I defined a new constructor-with a different signature, the newly defined constructor in the composed class is merged as well to the original class's constructor (even the composition rules don't merge them).

I want to no if it is possible to override a classs constructor by defining a new constructor with the same signature? And if the fact that the constructors are merged is done systematically for a certain reason that I ignore?

My example is :

package basePackage;
public class Context() {
public Context() {System.out.println(basePackage.Context: new Context());}
public void interface(){}
}

strategyPackage;
public class Context() {
private int strategy=0;
public Context(int strategy_fromUser) {
System.out.println(strategyPackage.Context: new Context());
strategy=strategy_fromUser;}

public void interface(){
switch (strategy) {
1: // behaviour 1
break;
2: // behaviour 2
break;
// ...
default: //the default behaviour}}
}

In my single control file (.opt) I only specify the general integration relationship which is the overrideByName: when I invoke my <init>(int) the result is :
basePackage.Context: new Context()
strategyPackage.Context: new Context()
Is this logic???

Point your RSS reader here for a feed of the latest messages in all forums