(Version 1.0)
Maximo Prieto and Pablo Victory
LIFIA. Departamento de Informática.
Facultad de Ciencias Exactas.
Universidad Nacional de La Plata.
also Depto. de Computación. Fac. de Ccs. Exactas y Naturales.
Universidad Nacional de Buenos Aires.
Argentina maximo@info.unlp.edu.ar victory@info.unlp.edu.ar
Intent:
The intent of this pattern is to teach the concept of object identity and detect whether the students are having trouble grasping this concept.
Motivation:
Students have trouble grasping the identity concept in object oriented programming. This is especially true if the students have a structured programming background. Usually students want to put an identification code to each and every object they identify. This is usually the first step after they identify a class.
The vast majority of programming languages and database languages use variable names to distinguish temporary values or "objects". The are effectively mixing the concepts of addressability and identity. Most database management systems use identifier keys to identify rows, tuples or "persistent objects". The are mixing data value and identity. This distinction between the name of an object and the object itself or its identity is the kind of problem the Identity
pattern wishes to address.
Students with previous knowledge of traditional design technics have difficulty grasping the identity concept. Most probably, every tool and language they have used required that they define the key or index of the record, register or table they used. They tend to carry this practice into object oriented programming. They can not understand how any entity can still be the same entity even when its "code" has changed. Moreover, they have problems understanding how two different objects, let',s say object A and object B, can reference a third object (object C) by a different name each. They can not conceive how; if object C is changed by object A, the change can be seen by
object B too.
Applicability:
Use the Identity Problem pattern when:
Students tend to put a "code" or identifier field to every object they create and manipulate.
Students end up implementing messages, in domain model objects, like:
#rentCar: aPlateNumber toClient: aName
Note that both objects, the car and the client who wants to rent it, are represented by their corresponding "identifier code". You want to teach the identity concept to new students with no prior background in computer science.
Structure:
They should model problems in which the identity of the objects is the key to solve them. These exercises should present them with objects whose identity can not be determine in the traditional way. For example:
Implement a chess (or checkers) game for two human players. Model the board and the pieces. The user should be able to select any piece from the board and obtain a report of the next five moves that piece will perform during the course of a normal chess game.
The problem is correctly solved if:
Each piece is a single different object.
Each cell in the board is a single different object.
No identity code is used to identify each of the different pawns, rooks, bishops or knights of any color.
Consequences:
The Identity pattern should help students understand that:
Identity is that property of an object which distinguishes it from all other objects, regardless its internal state.
The identity of an object is preserved even when the state of that object is completely changed.