classes and objects: the building blocks of the object-oriented paradigm presented by tara struble

Post on 18-Jan-2016

212 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Classes and Objects:Classes and Objects:The Building Blocks of the The Building Blocks of the Object-Oriented ParadigmObject-Oriented Paradigm

Presented by Tara StrublePresented by Tara Struble

Introduction to Classes and Introduction to Classes and ObjectsObjects

All implementation details should be All implementation details should be hidden from users behind a hidden from users behind a consistent public interface.consistent public interface. Allows designer to change Allows designer to change

implementation whenever necessary.implementation whenever necessary. Greatly simplifies maintenance.Greatly simplifies maintenance.

Messages and MethodsMessages and Methods

Message Message name of an object name of an object behavior.behavior.

Method Method implementation of a implementation of a message.message.

Protocol Protocol list of messages to which list of messages to which an an object can respond. object can respond.

Users of a class must be dependent on Users of a class must be dependent on its public interface, but a class should its public interface, but a class should not be dependent on its users.not be dependent on its users.

Minimize the number of messages in Minimize the number of messages in the protocol of a class.the protocol of a class.

Implement a minimal public interface Implement a minimal public interface that all classes understand.that all classes understand. (operations such as copy, equality testing, (operations such as copy, equality testing,

printing, parsing from an ASCII description)printing, parsing from an ASCII description)

Do not put implementation details Do not put implementation details such as common-code private such as common-code private functions into the public interface of functions into the public interface of a class.a class.

Do not clutter the public interface of Do not clutter the public interface of a class with items that users of that a class with items that users of that class are not able to use or are not class are not able to use or are not interested in using.interested in using.

Class Coupling and Class Coupling and CohesionCohesion

The goal is tight cohesion within classes The goal is tight cohesion within classes and loose coupling between classes.and loose coupling between classes. Tight cohesion implies that the code Tight cohesion implies that the code

making up the function is closely related.making up the function is closely related. Loose coupling implies that when one Loose coupling implies that when one

function wishes to use another, it should function wishes to use another, it should enter and exit the function from one point.enter and exit the function from one point.

Basic forms of couplingBasic forms of coupling

Nil couplingNil coupling two classes that have no two classes that have no dependency on each other.dependency on each other.

Export couplingExport coupling one class is dependent one class is dependent on the public interface of the other.on the public interface of the other.

Overt couplingOvert coupling one class uses the one class uses the implementation details of another class implementation details of another class with permission.with permission.

Covert couplingCovert coupling same as overt coupling, same as overt coupling, except that no permissions are granted.except that no permissions are granted.

Classes should only exhibit nil or Classes should only exhibit nil or export coupling with other classes.export coupling with other classes.

A class should capture one and only A class should capture one and only one key abstraction.one key abstraction.

Keep related data and behavior in Keep related data and behavior in one place.one place.

Spin off non-related information into Spin off non-related information into another class.another class.

Dynamic SemanticsDynamic Semantics

Collection of all possible states of a Collection of all possible states of a class’s objects, as well as the legal class’s objects, as well as the legal transitions between them.transitions between them.

Allows an object to respond Allows an object to respond differently to the same message sent differently to the same message sent at different times.at different times.

Abstract ClassesAbstract Classes

Do not know how to instantiate Do not know how to instantiate objects.objects.

Used primarily for inheritance Used primarily for inheritance hierarchies.hierarchies.

Roles Versus ClassesRoles Versus Classes

Be sure the abstractions that you Be sure the abstractions that you model are classes and not simply the model are classes and not simply the roles objects play.roles objects play. The distinction is based on differing The distinction is based on differing

behavior.behavior.

top related