Professional Documents
Culture Documents
Jin Sa
Session Aims
introduce the concept of objects and classes. present methods for identifying classes given textual descriptions of required system functionality. illustrate the benefits of highly cohesive loosely coupled classes. explain the UML class and object notion. introduce the term encapsulation and show the benefits of applying encapsulation to classes.
One instance of the Film class could contain details of the film The Godfather and another The Dark knight. Each of the instances stores exactly the same type of data, film name, certification and classification yet each one represents a different film.
CRC Process
Once you have a reasonable list of candidate classes in your OO design you can further evaluate their place in a particular system by identifying their responsibilities
what they do, and who they need to work with to do this their collaborations. The process is referred to as the Classes Responsibilities and Collaborations process or more commonly as the CRC process.
CRC process
write the names of all candidate classes on a series of cards. work through the textual narrative of the system requirements, i.e. the use case descriptions assigning responsibilities to classes, e.g. determining doing something, knowing something and decision making. Classes that have no responsibilities can be removed because they do not add value to the system
Example
Abstractions drawn from a retail problem domain could include: Customer, Order, Product, Shipment, Invoice and Warehouse. Abstract such as Transaction is a solution related abstraction.
Encapsulation
encapsulation refers to the process of an object controlling outside access to its internal data. Client only knows how to call the methods, not how the methods are implemented. Data attributes are made private, i.e. protected from being directly accessed from outside Visible methods (services) are made
Benefits of encapsulation
The main benefit of encapsulation is that the programmer may change the implementation of the object without affecting the whole program, if he or she preserves the interface of the object. Any change of the data representation will affect only the implementation of the methods. By keeping data private and providing public welldefined service methods the role of the object becomes clear to other objects. This increases usability.
Recap
Classes exist in code and are the blueprints used to create objects Objects are instances of classes and exist at runtime A common modelling technique is to model the vocabulary of the system. Encapsulation is achieved by making data private and services public We seek to develop classes that are highly cohesive and loosely coupled.
Student activity
Complete student activity 3.2