Ideas:chad3f:RPFramework: Difference between revisions
Content deleted Content added
imported>Chad3f |
imported>Chad3f |
||
| (72 intermediate revisions by the same user not shown) | |||
Line 39:
This has the following problems/short-comings:
- The assigned parent is typically assigned by name, rather than object, which can make it prone to spelling errors. If you're lucky, it will throw an exception, if not a hard to track problem may arise. Also passing the name means a common base class has to be resolved several times.▼
▲
=== Proposed Replacement ===
Using static RPClass
The replacement code would look like:
Line 56 ⟶ 55:
class SomeClass extends RPObject {
public static final RPClass RPCLASS = createRPClass();
private static RPClass createRPClass() {
RPClass rpclass = new RPClass("some");
Line 66 ⟶ 65:
class OtherClass extends SomeClass {
public static final RPClass RPCLASS = createRPClass();
private static RPClass createRPClass() {
RPClass rpclass = new RPClass(SomeClass.RPCLASS, "other");
Line 73 ⟶ 72:
}
}
class AnotherClass extends SomeClass {
public static final RPClass RPCLASS = createRPClass();
private static RPClass createRPClass() {
RPClass rpclass = new RPClass(SomeClass.RPCLASS, "another");
Line 91 ⟶ 90:
In this code, when one of these java classes is loaded, the static initializer will automatically call it's createRPClass() method. If the class has a super-RPClass [such as OtherClass.createRPClass() uses], before the reference to SomeClass.RPCLASS is used, the JVM will have loaded SomeClass and called it's createRPClass().
If the parent RPClass is only assignable during the constructor of sub-classes [i.e. normal use of isA() goes away], then it will be more obvious that the parent has been omitted. Of course, someone could always call the RPClass constructor with no parent argument, and still forget the super, unless the only constructor(s) available required the parent, in which case the
Benefits:
----
== Message Protocol ==
Line 108 ⟶ 110:
''TBW''
----
[[Ideas:chad3f|Back to Ideas]]
| |||