Simulating Multiple Inheritance in Java

Problem:

I am trying to obfuscate code and create wrapper classes to access code implementation. Problem is that some parameters in methods have different types. (i.e.

public class Example{

ExampleImpl exampleImpl;

public void setExample(Problem exam) {

exampleImpl.setExample(exam);//complile error

//error message: problemImpl is not of type problem

}

}

public class ExampleImpl {

public void setExample(ProblemImpl exam) {

//do something

}

The objects Problem and ProblemImpl are abstract class that provode some implementation.

I know I have to sumulate multipule inheritance but its really have to changed the abstract classes to inherate each other. Problem with that is the ProblemImpl abstract class will be obfuscated.

Any suggestions.

[843 byte] By [sean1414a] at [2007-10-2 7:03:10]
# 1
Creating interfaces and classes will not help you obfuscate your code. This is not the reason behind using interfaces. If you want to obfuscate your code you should use an obfuscator like Proguard ( http://proguard.sourceforge.net)
beradriana at 2007-7-16 20:33:33 > top of Java-index,Other Topics,Patterns & OO Design...
# 2

I understand I need an obfucator to mangle my code, but I only want the implimentation to get obfucated. I will then create an api class that is a skelton of my implementation class.

e.i

//My API - Skelton of Impl class

class example{

ExampleImpl impl;

public setExample(Problem api) {

impl.setExample(api) //Compile error since Problem is of another type

}

//My implementation

class exampleImpl {

public void setExample(ProblemImpl impl) {

//My implmemetation code

}

Rule: Implementations can only talk to other Implementations.

sean1414a at 2007-7-16 20:33:33 > top of Java-index,Other Topics,Patterns & OO Design...
# 3
What makes you think that anyone would want to reverse engineer your code in the first place?
jschella at 2007-7-16 20:33:33 > top of Java-index,Other Topics,Patterns & OO Design...
# 4
Management wants it done. The program has some workflow code that needs to be hidden.
sean1414a at 2007-7-16 20:33:33 > top of Java-index,Other Topics,Patterns & OO Design...
# 5
> but I only want the implimentation to get obfucated.Then you should use the obfuscator only on the implementation.
beradriana at 2007-7-16 20:33:33 > top of Java-index,Other Topics,Patterns & OO Design...
# 6
Right, the implementation is the only code that will be obfucated but I still need to created a wrapper for the obfucstacted objects so our clients can implement there own code.
sean1414a at 2007-7-16 20:33:33 > top of Java-index,Other Topics,Patterns & OO Design...
# 7

> Right, the implementation is the only code that will

> be obfucated but I still need to created a wrapper

> for the obfucstacted objects so our clients can

> implement there own code.

The obfuscator should have options that allow you to tune it. Some but not all of the API should be public. You should set it so it doesn't mess with those.

jschella at 2007-7-16 20:33:33 > top of Java-index,Other Topics,Patterns & OO Design...
# 8

> Right, the implementation is the only code that will

> be obfucated but I still need to created a wrapper

> for the obfucstacted objects so our clients can

> implement there own code.

I don't see exactly what the problem is. You create your API, you implement it and you obfuscate only the implementation (the obfuscator should give you a way to do so). In this way your clients can implement the API and you have your implementation obfuscated.

beradriana at 2007-7-16 20:33:33 > top of Java-index,Other Topics,Patterns & OO Design...