Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSC238 INTRODUCTION TO OOP Chapter 1.

Similar presentations


Presentation on theme: "CSC238 INTRODUCTION TO OOP Chapter 1."— Presentation transcript:

1 CSC238 INTRODUCTION TO OOP Chapter 1

2 Objectives At the end of this topic, you should be able to
know the elements of an object. differentiate between objects and classes. understand the characteristics of OOP. NH2008

3 Object Objects are key to understanding object-oriented technology.
In real life, things that you see such as cars, trees, cats, mobile phones and so on are objects. Even, you as a student is an object. Each object has states , behaviours and identity. NH2008

4 Elements of an Object OBJECT
Attribute /state – properties used to define characteristics. OBJECT Behaviour – means the object can perform actions & can have actions performed on it. Identity – means the object can be called & used as a single unit. NH2008

5 Example 1: An air-conditioner at MK02 State : Turn on Current temperature is at 20 degree celcius Behaviours : Change the temperature level NH2008

6 Example 2: A Siamese Cat State : Dark brown colours on its face, ears and feet Behaviours : Playing, fighting, hunting NH2008

7 Example 3: How about the following cats? They are 3 different cats which two of them are of the same type. What makes them different?  their states , behaviours and identity. NH2008

8 Example 4: Different types of cats Share the same behaviours NH2008

9 Example 5: How about these cars?
Try to identify their common attributes and behaviours . NH2008

10 Lesson Learned… What can you tell from example 3 to 5?
A group of animals or things that are similar in some way. They share the same attributes and behaviours. This group of objects represents a class. NH2008

11 Class ? Object ? Class Object a kind of template.
represents the common structure & behaviour shared by the same type. A collection of objects of similar type. must be defined before creating an instance of the class. a thing, both tangible and intangible. is comprised of data & operations that manipulate these data. is called an instance of a class. NH2008

12 Example 6: Variables Represents the data/ attributes variables.
Student name id setName() setId() Represents the data/ attributes variables. a set of properties Methods class Represents the behaviours. A sequence of instructions that a class or an object follows to perform a task. : Student name=“Sarah” id=“1234” object / instance of the class NH2008

13 Messages An object can’t exist on its own.
An object communicates with other objects. Therefore, a message is used to instruct a class or an object to perform a task. An object or a class only responds to messages that it can understand. Messages must match the method that it possess. A list of messages is called an interface. NH2008

14 Characteristics of OOP
Abstraction Encapsulation Inheritance Polymorphism NH2008

15 Characteristic of OOP Abstraction Encapsulation
the act of representing essential features without including the background details or explanations. Use to manage complexity Abstraction can be managed through the use of hierarchical classifications. The mechanism that binds together code and the data it manipulates and keeps both safe from the outside interference and misuse. Access to the code & data inside the wrapper is tightly controlled through a well-defined interface. NH2008

16 Example 7: Variables: name student id address course Methods:
changeAddress(String) changeCourse(String) Student INTERFACE changeAddress(String) changeCourse(String) NH2008

17 Characteristics of OOP
Inheritance The process by which one object acquires the properties of another object. An object need only to define all those qualities that make it unique within its class. It inherits its general attributes from its parent. A subclass has at least one attribute/method that differs from its superclass Other names :base class-derived class, parent class-child class NH2008

18 Example 8: Mobile Phone MobilePhone model manufacturer price …
CameraPhone model manufacturer price pixel MobilePhone model manufacturer price PdaPhone model manufacturer price memoryCap subclass superclass subclass NH2008

19 Characteristics of OOP
Polymorphism From the Greek, meaning “many forms”. A feature that allows one interface to be used for a general class of actions. “one interface, multiple methods” Can be applied in the overloaded methods (a few methods that have the same name but with different parameters). NH2008

20 Example 9: Class : Rectangle Variables : length, width, height
Methods : …. displayShape(char simbol) displayShape(int a) This class has 2 methods with the same name but with different type of parameters NH2008

21 Conclusion Elements of an object are attribute, behaviour and identity. A class is a collection of objects of similar type. An object is comprised of data and operations that manipulate these data. Characteristics of OOP is abstraction, encapsulation, inheritance and polymorphism. NH2008


Download ppt "CSC238 INTRODUCTION TO OOP Chapter 1."

Similar presentations


Ads by Google