body { margin:0; padding:0; font-family:times; font-size:9pt; } p { margin-top:5; margin-bottom:5; font-weight:plain; font-family:serif; font-size:9pt; } h1 { margin-top:5; font-size:16pt; font-weight:bold; text-align:center; font-family:sans-serif; } h2 { margin-top:20; font-size:10pt; font-weight:bold; text-align:left; font-family:sans-serif; } pre { color:#993333; font-size:9pt; } code { color:#993333; } .section { text-align:justify; padding:5; }
The CTCMap class provides direct declarative support for the implementation
of object associations.
Okay, we need to take a couple of steps back.
When you define an object model, you are aware of the kind of associations that exist between different objects.
When you implement such a model using java you will select a number of utility
objects, such as ArrayList and LinkedList to help you to provide
such associations. You will probably write a number of different methods to help you
maintain and manage the associations.
If you are using a database, you will probably not worry about the java
associations. Instead you may query the data stored in different tables.
In a database, the object associations are implicit in the data stored in the tables. The data is used to imply the intended association:
SELECT * FROM EMPLOYEES WHERE COMPANY = "The Company".
...or somesuch.
The reason this works is because the database provides a global access mechanism.
Now, it would be possible to do something similar with an "in-memory" database model, but that would really be a little unimaginative.
With CTCMap the associations are managed directly using a combination
of double-linked lists and property keys.
The effect of these structures can be demonstrated simply:
import cutthecrap.ctc.CTCMap;
public class Demo {
public void main(String[] args) {
CTCMap c = CTCMap();
c.set("name", "A CTCMap");
CTCMap p = CTCMap();
p.set("name", "Another CTCMap");
c.set("parent", p);
System.out.println("The object '" + p.get("name")
+ "' is refernced by 'parent' by "
+ p.getLinkSet().size() + " objects" );
}
}
Running java Demo should result in
The object 'Another CTCMap' is referenced by 'parent' by 1 objects
printed to the console.
Well an idiom can be thought of as a low-level pattern that provides some useful functionality. Hence, for example, the "intelligent pointer" idiom used by many C++ programmers.
The common idioms that are used by java programmers include:
classes, iterations, lists, maps, threads and exceptions.
Useful idioms support the use of a specific paradigm - such as "procedural programming".
As mentioned already, programmers have learnt how to use the various idioms available to
implement systems. But aside from the "class" idiom, none of the patterns available really
support "object orient programming". For this an approach to representing object associations
in a sensible way is required. This is what CTCMap addresses.
The most obvious use for CTCMap is as a base class to be extended to
implement required Interfaces.
public class Child extends CTCMap {
static final String m_parent = "child/parent":
public void setParent(Parent parent) {
set(m_parent, parent);
}
public Parent getParent() {
return (Parent) get(m_parent);
}
}
public class Parent extends CTCMap {
Iterator getChildren() {
return getLinkSet(Child.m_parent).iterator();
}
}
Alternatively it could be used as a private "connection" object to which requests are
delegated. With this approach each "public" object would maintain a single private
CTCMap, these objects would themselves be extended CTCMaps to
support retrieval of their "real" objects.
public class DelegateCTCMap extends CTCMap {
Object m_real;
public DelegateCTCMap(Object link) {
m_real = link;
}
Object getReal() {
return m_real;
}
}
But this approach does require significant protocol support.
CTCMap implements a subset of the generic model. For more information
visit the main website.