CSC435 Object-Oriented Programming Introduction PDF

Summary

This document provides an introduction to object-oriented programming (OOP). It covers the basic concepts of OOP, including the definition of objects, classes, attributes, and behaviors. The document also explores the benefits of using OOP in software development, such as cost-effectiveness and efficiency.

Full Transcript

CSC435: Object Oriented Programming Topic 1 – Introduction to Object Oriented Programming 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...

CSC435: Object Oriented Programming Topic 1 – Introduction to Object Oriented Programming 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 CONTENTS INTRODUCTION TO OBJECT INTRODUCTION TO OBJECT Object is a thing; tangible & intangible Tangible objects are objects that we can see & touch such as people (student, staff employee, etc) and vehicle (car, bike) Intangible objects are objects that we cannot see & touch such as laws, policies, events, accounts, etc. INTRODUCTION An object has attribute and behavior. In OOP, objects are the collection of: Fields (object state, data members, instance variables,..) TO OBJECT Methods (behaviors, …) Example: Bicycles have state (current gear, current pedal cadence, current speed) and behavior (changing gear, changing pedal cadence, applying brakes). ELEMENTS OF OBJECT ELEMENTSOFOF ELEMENTS ANOBJECT OBJECT Attribute State INTRODUCTION TOBehaviour OBJECT ELEMENTS OF AN OBJECT Attribute The relevant data that relate with the object Also known as state or field or variable Example data for car object Color Model INTRODUCTION TO OBJECT ELEMENTS OF OBJECT ELEMENTS OF AN OBJECT Behaviour Means the object can perform actions & can have actions performed on it. Also known as methods or functions Example for the operation on car Moving Changing gear Stop INTRODUCTION TO OBJECT ELEMENTS OF OBJECT ELEMENTSState OF AN OBJECT  State  The description about the data (fields/attribute) contained in an object at any point in time  Example: ◼ Car have state (color, model) INTRODUCTION ◼ State 1: blue, toyota ◼ State 2: red, honda  TO OBJECT If the data changed, means the state is changed ELEMENTS OF OBJECT ELEMENTS OF AN1 OBJECT EXAMPLE INTRODUCTION TO OBJECT ELEMENTS OF AN2 OBJECT EXAMPLE INTRODUCTION TO OBJECT ELEMENTS OF AN3OBJECT EXAMPLE INTRODUCTION TO OBJECT ELEMENTS OF AN4OBJECT EXAMPLE INTRODUCTION TO OBJECT ELEMENTS OF AN OBJECT What can you tell from the example 1 to 4 ?  A group of animals or things that are similar in some way. INTRODUCTION  They share the same attributes and behaviours.  This group of objects represents a class. TO OBJECT Class vsOFObject ELEMENTS AN OBJECT INTRODUCTION TO OBJECT ELEMENTS OF AN5OBJECT EXAMPLE INTRODUCTION TO OBJECT Understand the concept of Java Classes and Objects with ELEMENTS OF AN OBJECT an example. Let's take an example of developing a pet management system, specially meant for cats. You need to model real-life beings, i.e., cats into INTRODUCTION software entities. How to convert real life entities cats into software objects? TO OBJECT Understand the concept of Java Classes and Objects with ELEMENTS OF AN OBJECT an example. INTRODUCTION TO OBJECT Understand the concept of Java Classes and Objects with ELEMENTS OF AN OBJECT an example. INTRODUCTION TO OBJECT Understand the concept of Java Classes and Objects with ELEMENTS OF AN OBJECT an example. INTRODUCTION TO OBJECT Understand the concept of Java Classes and Objects with ELEMENTS OF AN OBJECT an example. INTRODUCTION TO OBJECT Example Code: Class and Object ELEMENTS OF AN OBJECT INTRODUCTION TO OBJECT Why OOP is chosen? ELEMENTS OF AN OBJECT Current problem of software: Software is difficult to develop, maintain and modify. Most software is over budget and delivered late. INTRODUCTION Programmers still have to create software from the ground-up. TO OBJECT OOP introduces techniques that help: Developing a more cost-effective and efficient software that will be delivered on time. Adapt quickly to new changes or client demand CHARACTERISTICS OF OOP ELEMENTS OF AN Characteristics OBJECT of OOP Abstraction Encapsulation Inheritance INTRODUCTION Polymorphism TO OBJECT ELEMENTS OF AN OBJECT Abstraction the act of a software module containing relevant characteristics of the object to be represented (designing classes) Object modeling is based on data that can be stored and functions, which are to manipulate the data. INTRODUCTION Type of objects are declared in program thru class. Different programmer may model an object from different class TO OBJECT hierarchical classifications. ELEMENTS OF AN OBJECT Encapsulation To encapsulate means to enclose in a capsule. It is a way of packaging information. In OOP data (attributes) and methods(behavior) are encapsulated into container called classes. INTRODUCTION Classes have the property of data hiding. Data hiding – declaring the object data to be private so it will not be TO OBJECT accessible by non-member modules This means although objects may know how to communicate with one another thru interface, normally the object is not allowed to know how other objects are implemented. ELEMENTS Inheritance - theOF ANofOBJECT use extends 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 INTRODUCTION Other names :base class-derived class, parent class-child class TO OBJECT An Inheritance Hierarchy ELEMENTS OF AN OBJECT INTRODUCTION TO OBJECT ELEMENTS OF ANphone EXAMPLE 6: Mobile OBJECT INTRODUCTION TO OBJECT ELEMENTS OF AN OBJECT Polymorphism Poly means many. Morphism means forms. Polymorphism feature enables classes to provide different implementation of methods having the same name. INTRODUCTION A feature that allows one interface to be used for a general class of actions. TOmethods” “one interface, multiple OBJECT Can be applied in the overloaded methods (a few methods that have the same name but with different parameters). ELEMENTS OFexample Polymorphism: AN OBJECT 6 INTRODUCTION TO OBJECT ELEMENTS OF AN OBJECT 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. INTRODUCTION Characteristics of OOP is abstraction, encapsulation, inheritance and polymorphism. TO OBJECT Quiz ELEMENTS OF AN OBJECT INTRODUCTION TO OBJECT ELEMENTS StructureOF AN OBJECT question As a programmer you asked to develop a program for keeping track of stock in a grocery store. The stock consists of variety of products. Each product has product number and product name. Based on the above scenario, name the appropriate class and its INTRODUCTION attributes. TO OBJECT

Use Quizgecko on...
Browser
Browser