OBJECT BASICS OBJECTS Object means a combination of
OBJECT BASICS
OBJECTS � Object means a combination of data and logic that represents some real world entity. � Ex: automobile. � Data can be car color, name, price, number of seats � Logic can be the collection of programs like show mileage, change mileage, stop, go.
A More Formal Definition : � An object is an entity with a well-defined boundary and identity that encapsulates state and behavior. � State is represented by attributes and relationships. � Behavior is represented by operations, methods, and state machines.
STATE State is a condition or situation during the life of an object, which satisfies some condition, performs some activity, or waits for some event. � The state of an object normally changes over time. Ex: Object Name: J Clark States: Employee ID: 567138 Date Hired: July 25, 1991 Discipline: Finance Maximum Course Load: 3 classes �
BEHAVIOR Behavior determines the collection of methods that describes what an object is capable of doing. � The visible behavior of an object is modeled by a set of messages it can respond to (operations that the object can perform). Object Clark’s behaviors: � Set Max Load() � Submit. Final. Grades() � Accept. Course. Offering() � Professor Clark() �
CLASSES � In the context of object-oriented systems, class is a set of objects that share a common structure and the common behavior. � Class is a specification of structure (instance variables), behaviors (methods) and inheritance. � Each object is an instance of the class.
ATTRIBUTES � An attribute is a named property of a class that describes the range of values that instances of the property may hold. � A class may have any number of attributes or no � attributes at all. Ex: Attributes of Student class: � - name � - address � - student. ID � - date. Of. Birth
Example: Course (Class) Properties/Attributes: � Name � Location � Days offered � Credit hours � Start time � End time Behaviors: � Add a student � Delete a student � Get course roster � Determine if it is full
OBJECTS RESPOND TO MESSAGES � To perform any operation a message is sent to an object. � The object performs operation based on the message that receives. � Different objects can respond to the same message in different ways. � For example cars, cycle, bike will respond to STOP message but operations performed by those objects are different.
METHODS AND MESSAGES � The message is the instruction and method is the implementation (details of what operations need to be performed upon the received message). � An object understands a message when it can match the message to a method, which has the same name as the message.
ENCAPSULATION AND INFORMATION HIDING � Encapsulation means the user cannot see the inside of the object but can use the object by calling the object’s methods. � The object- oriented languages provide encapsulation with public, private and protected.
CLASS HIERARCHY � Object-oriented system organizes classes into super class-subclass hierarchy. � The top classes on the hierarchy are most generic classes. � Bottom classes are most specific. � Subclass inherits all of the properties and methods of the super class and also having some specific properties and behaviors.
EXAMPLE Motor vehicle CAR BUS School bus Govt bus Race Car Personal car
POLYMORPHISM � Same operation may behave differently on different classes.
OBJECT RELATIONSHIP AND ASSOCIATIONS � � � Association represents the relationships between objects and classes. � Example: a pilot can fly planes Associations are bidirectional. The direction implied by the name is forward direction; The opposite direction is the inverse direction. An important issue in association is cardinality, which specifies how many instances of one class relate to a single instance of an associated class. Often is described as "one" or "more". Faculty Course Teaches by taught
CONSUMER-PRODUCER RELATIONSHIP Also known as client-server association or a use relationship. � The consumer-producer relationship can be viewed a one-way interaction: one object requests the service of another object. � The object that makes the request is the consumer or client, and the object that receives the request and provides the service is the producer or server. � Print. Server Request for Printing Item
AGGREGATION � Objects are composed of /may contain other objects. Car Engine Seat Wheel
- Slides: 17