ObjectSystemPatterns are those patterns used in OO system infrastructure.
Some standard patterns are:
- TypeSystem = tools and conventions for DesignByContract (see TypesAreContracts)
- BaseObjectClass? = parent class of "everything."
- ObjectIntrospection? = meta-data available to running program.
- PrimitiveTypes? = language supported types and structures, from which other objects are built.
- PolymorphismStrategy? = how to design for polymorphic behavior.
- '...others?'
Example: JavaLanguage
- TypeSystem is implemented by class and interface keywords, and primitive types.
- BaseObjectClass? is java.lang.Object.
- ObjectIntrospection? is provided by some classes in java.lang and the package java.lang.reflect; interaction with the garbage collector is provided by the package java.lang.ref and the finalize method of the root Object class.
- There are 8 PrimitiveTypes?, plus arrays.
- PolymorphismStrategy? = class inheritance (any method not declared "final"), and interfaces.
Example: JavaScript
- TypeSystem is dynamic, implemented by primitive types, "function.prototype" construct and "new" keyword.
- BaseObjectClass? = Object and Object.prototype (which can have user-defined properties and methods)
- ObjectIntrospection? = enumeration of objects and object members (which are not marked DontEnum?) with the use of "for...in" statement.
- PrimitiveTypes? = Undefined, Null, Boolean, Number and String. These (Boolean, Number, String) are also first class objects, which can have user-defined properties and methods.
- PolymorphismStrategy? = methods with same signature (by name, not typed) are polymorphic.
Example: C++
- TypeSystem = "class" keyword definition (a variation of C "struct"), and primitive types.
- BaseObjectClass? -- has none. (Inheritance hierarchies are usually independent.)
- ObjectIntrospection? = RunTimeTypeInformation (RTTI) -- limited to class names and safe "dynamic_cast<>()".
- PrimitiveTypes? = wide range of traditional types. Known for easy (and questionable) conversion between types, heavy use of pointers, and operations on pointers.
- PolymorphismStrategy? = pointer or reference to common base class, calling "virtual" method with exact same function signature.
Example: SmalltalkLanguage
- TypeSystem is implemented by class definitions (through IDE in most cases).
- BaseObjectClass? = Object.
- ObjectIntrospection? = direct interaction with class object.
- PrimitiveTypes? = String, Integer, and array. These are also first class objects, which can have user-defined methods.
- PolymorphismStrategy? = methods with same signature (by name, not typed) are polymorphic.
Example: PythonLanguage
- TypeSystem is dynamic, classes defined by the keyword class
- The BaseObjectClass? doesn't seem to have a name, as Python doesn't give names to types. However it has observable characteristics.
- ObjectIntrospection? is a strong point of the language - you can access an object's namespace as if it was a field of the object.
- There are primitive types, plus sequences, tuples, dictionaries.
- PolymorphismStrategy? = ???
Example: CORBA
- TypeSystem is implemented by IDL
- BaseObjectClass? is only revealed in language bindings - in Java it is org.omg.CORBA.Object.
- ObjectIntrospection? is implemented by the CorbaInterfaceRepository?.
- There are a few PrimitiveTypes?, plus arrays and structs.
- PolymorphismStrategy? = implement or inherit from common interface.
Example: COM/DCOM
- TypeSystem is implemented by IDL. (...but can come from native language constructs, a la VB.)
- BaseObjectClass? = IUnknown.
- ObjectIntrospection? = type libraries, ITypeInfo interface, and IUnknown::QueryInterface at run time.
- PrimitiveTypes? = most C types, struct and array.
- PolymorphismStrategy? = object that implement the same interface are polymorphic.
Example: PhpLanguage
- TypeSystem is dynamic and implemented by class keyword, and primitive types. PHP5 Allows Type Hinting on class arugments and interfaces.
- BaseObjectClass? is stdClass. (in php5) The base Exception Class is Exception
- ObjectIntrospection? is provided by some very basic reflection functions. In PHP5 reflection is provided by the Reflection Base Class, along with it's subclasses.
- Primitives are: Booleans, Integers, Floating point numbers, Strings, Arrays, Resources
- PolymorphismStrategy? = class inheritance. "Final" keyword added in PHP5, and interfaces have been added.
See also
DesignPatternsForDistributedObjects.
[ClassSystem? changed to TypeSystem, as suggested by ldn-lrs-dns-01.imagegen.net.]
We might also want to think about Reflection; languages like SmallTalk and Lisp (CLOS) allow you to actually get to the class meta-object and manipulate it, Java is much more restrictive.
Isn't JavaReflection? already covered by ObjectIntrospection?? – JeffGrigg
Yes, but introspection doesn't sound quite the same as reflection. I would have though it's about querying your environment, whereas reflection allows you to change it.
I don't think Smalltalk has a primitive type, except perhaps for the oop (object pointer). As for TypeSystem, I don't think it has a "type as contract" kind of feel. - AllanBaruz