generische Lösungen wiederkehrender Design-Probleme durch
Frameworks für spezielle Zwecke
Architektur-Patterns
Design-Patterns
Implementierungs-Patterns, Idiome
public class Binärer_Suchbaum
{
Knoten wurzel = null;
public
void einfügen (Schlüssel s) {
wurzel = einfügen (wurzel, s);
}
private
Knoten einfügen (Knoten k, Schlüssel s) {
if (k == null) {
return new Knoten (s);
} else if (s < k.schlüssel) {
k.links = einfügen (k.links, s);
return k;
} else if (s > k.schlüssel) {
k.rechts = einfügen (k.rechts, s);
return k;
} else {
// throw new SchlüsselSchonDrin ();
}
}
}
oder streng funktional mit Neuaufbau des Baumes:
return new Knoten (k.schlüssel, einfügen (k.links, s), k.rechts);
Plattform-Abstraktionsschicht (Framework)
Vermeidung von Objekterzeugungen (recycelnde Factories,
Programmierdisziplin). Konflikt mit Objektorientierung.
Kontextsicherungskonzept.
spezielles Framework und Programmiermodell
Verhandlung des Interfaces
Dokumentation und Konformitätsanalyse der externen
Interaktion einer Komponente
strenges mehrstufiges Testverfahren
public class XYHandleFactory
implements IComponentHome, IFactory
{
private
IContainer _container;
public
void set_container (IContainer container)
{
_container = container;
}
private
Handle [] _handles;
/**
Setup of n handles. Called by component users.
*/
public
void start (int n)
{
_handles = new Handle [number];
for (int i = 0; i < _handles.length; i ++) {
_handles [i] = new Handle (_container, ...);
}
}
/**
Invoked by Framework when the container terminates.
Resources must be released.
*/
public
void on_container_termination ()
{
for (int i = 0; i < _handles.length; i ++) {
if (_handles [i].is_in_use ()) {
_handles [i].cleanup ();
}
}
}
/**
Acquire one of the configured handles.
@param tag the index of the registered handle to use
@param id the data ID to use by the handle
*/
public
IHandle get_handle (int tag, long id)
throws FrameworkException
{
if (i < 0 || i >= _handles.length) {
throw new HandleException (FAC_no_handle);
}
Handle handle = _handles [i];
if (handle.is_in_use () && (handle.getID () == id)) {
handle.continue_use (_container);
return handle;
} else if (! handle.is_in_use ()) {
handle.new_use (_container, id);
return handle;
} else {
throw new HandleException (FAC_handle_in_use);
}
}
/**
Release handle. Free resources (e.g. to their pools).
*/
public
void release (IHandle handle)
{
((Handle) handle).cleanup ();
}
}
abstract class HandleControl
implements ITimerListener
{
/**
Setup context for initial or continuing handle use.
*/
private
void set_context (IContainer container) {
_container = container;
_container.setup_timer (_timer_id, this);
}
/**
Invoked on timer time-out via registered ITimerListener.
*/
abstract
void timeout ();
synchronized
void new_use (IContainer container, long id) {
set_context (container);
_container.set_context_var ("handle id", id);
}
synchronized
void continue_use (IContainer container) {
set_context (container);
}
}
public class Handle
extends HandleControl
{
public
long get_square () {
long id = _container.get_context_var ("handle id");
long value = DB.lookup_XY (id);
return value * value;
}
}