|
-
Nov 27th, 2005, 03:03 PM
#1
Thread Starter
Lively Member
Extend one object from multiple classes?
Hello, I'm a .NET developer who's been getting experience in Java for some time now, and I think I'd like to excercise it outside the classroom finally.
If you find it relevant, I'm using PircBot, an IRC client (http://www.jibble.org/pircbot.php).
The examples make it easy to see how it works, and it is well documented. I plan to do my own research for dynamically loading classes to represent plugins for it, but I would like to do something like this, to avoid a lot of code re-writing:
1. Load multiple classes dynamically (not really part of my qustion)
2. Extend the same PircBot abstract class instance across all of these classes, hopefully also allowing called methods that PircBot uses for events to all be called.
Is my only solution to create a "proxy" class to extend pircbot, then manually handle all pircbot events and loop through my plugins to raise them?
Thank you!
-
Nov 28th, 2005, 10:09 AM
#2
Fanatic Member
Re: Extend one object from multiple classes?
 Originally Posted by MalcolmCarmen
Hello, I'm a .NET developer who's been getting experience in Java for some time now, and I think I'd like to excercise it outside the classroom finally.
If you find it relevant, I'm using PircBot, an IRC client ( http://www.jibble.org/pircbot.php).
The examples make it easy to see how it works, and it is well documented. I plan to do my own research for dynamically loading classes to represent plugins for it, but I would like to do something like this, to avoid a lot of code re-writing:
1. Load multiple classes dynamically (not really part of my qustion)
2. Extend the same PircBot abstract class instance across all of these classes, hopefully also allowing called methods that PircBot uses for events to all be called.
Is my only solution to create a "proxy" class to extend pircbot, then manually handle all pircbot events and loop through my plugins to raise them?
Thank you!
You can use an Interface to do this. Not like a user interface, but an Interface Class. Look them up.
-
Nov 28th, 2005, 10:51 AM
#3
Re: Extend one object from multiple classes?
I don't get the problem. Can you show some theoretical code of what you want to do?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Dec 3rd, 2005, 02:52 PM
#4
Thread Starter
Lively Member
Re: Extend one object from multiple classes?
I'll provide some psuedo-code for a method that might load these plugin .class files:
method loadPlugins {
while(thereArePluginsToLoad)
NewPlugin.DynamicallyExtendAPluginClass(PircBotClass)
}
Now, I've supposedly extended PircBotClass to MULTIPLE classes. If PircBotClass raised an event like SayThis() and two plugins were loaded, the two plugin classes would have their SayThis() method invoked, seeing as they extend from a single instantiated object.
The utility of this is obviously to make it easy for multiple plugin classes to communicate with a single instance of the PircBot class I mentioned earlier. As PircBot events fire (such as a user joining a "chat room"), they will be fired across multiple classes rather than one.
PircBot is *supposed* to be used like this:
myclass extends pircbot {
..
}
I need to extend a SINGLE instance of pircbot across *multiple* classes - something that I hope java has the dyanmic ability to do.
Thank you so much!
-
Dec 3rd, 2005, 03:24 PM
#5
Re: Extend one object from multiple classes?
That's even conceptually impossible, not just practically. Inheritance works on the class level, not at the instance level.
Extend PircBot *once* with a special dispatcher class that maintains a list of your plugins and forwards the calls to each of them.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Dec 5th, 2005, 10:44 AM
#6
Thread Starter
Lively Member
Re: Extend one object from multiple classes?
 Originally Posted by CornedBee
That's even conceptually impossible, not just practically. Inheritance works on the class level, not at the instance level.
Extend PircBot *once* with a special dispatcher class that maintains a list of your plugins and forwards the calls to each of them.
Is it possible at all to "catch" the methods called and forward them to X class, or will I have to handle the event methods and then manually forward them? I could do this, but it won't be a fun chore since Pircbot has a good number of events.
-
Dec 5th, 2005, 11:18 AM
#7
Re: Extend one object from multiple classes?
Using java.lang.reflection.Proxy, it might be possible to catch everything. The code will be ugly, but short.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Dec 5th, 2005, 06:53 PM
#8
Thread Starter
Lively Member
Re: Extend one object from multiple classes?
 Originally Posted by CornedBee
Using java.lang.reflection.Proxy, it might be possible to catch everything. The code will be ugly, but short.
Thanks a lot, I'll look into using this. You've probably saved me a great deal of time :>
edit: for those like me:
http://java.sun.com/j2se/1.4.2/docs/...ect/Proxy.html
Last edited by MalcolmCarmen; Dec 5th, 2005 at 06:57 PM.
^_^
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|