Object Oriented Programming B.Sc. Digital MediaMultimedia Studio.

Slides:



Advertisements
Similar presentations
Introduction to Object Orientation System Analysis and Design
Advertisements

When is Orientated Programming NOT? Mike Fitzpatrick.
OOP Abstraction Classes Class Members: Properties & Methods Instance (object) Encapsulation Interfaces Inheritance Composition Polymorphism Using Inheritance.
Department of Computer Engineering Faculty of Engineering, Prince of Songkla University 1 5 – Abstract Data Types.
Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar Fundamentals of Web DevelopmentRandy.
OOP - Object Oriented Programming Object Oriented Programming is an approach to programming that was developed to make large programs easier to manage.
OBJECT ORIENTED PROGRAMMING M Taimoor Khan
Solutions to Review Questions. 4.1 Define object, class and instance. The UML Glossary gives these definitions: Object: an instance of a class. Class:
Object-Oriented Application Development Using VB.NET 1 Chapter 8 Understanding Inheritance and Interfaces.
Object-Oriented PHP (1)
Object Oriented Programming A brief review of what you should know about OOP.
Criteria for good design. aim to appreciate the proper and improper uses of inheritance and appreciate the concepts of coupling and cohesion.
Class Structures and Methods B.Sc. Multimedia ComputingMultimedia Authoring.
Object-oriented Programming Concepts
Object Oriented Programming B.Sc. Multimedia ComputingMultimedia Authoring.
INTRODUCTION TO JAVA PROGRAMMING Chapter 1. What is Computer Programming?
C++ fundamentals.
BACS 287 Basics of Object-Oriented Programming 1.
Inheritance using Java
UFCEUS-20-2 : Web Programming Lecture 5 : Object Oriented PHP (1)
Programming Languages and Paradigms Object-Oriented Programming.
Introduction to Object-oriented programming and software development Lecture 1.
© 2008 Dr. Paul Walcott – The University of the West Indies: Cave Hill CampusDr. Paul Walcott COMP6325 Advanced Web Technologies Dr. Paul Walcott The University.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
An Object-Oriented Approach to Programming Logic and Design
OBJECT ORIENTED PROGRAMMING CONCEPTS ISC 560. Object-oriented Concepts  Objects – things names with nouns  Classes – classifications (groups) of similar.
Object Oriented Programming CS160 - OOP. Objects Objects are a Objects are a way to organize and conceptualize a program as a set of interacting objects.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Microsoft Visual Basic 2008 CHAPTER ELEVEN Multiple Classes and Inheritance.
Features of Object Oriented Programming Lec.4. ABSTRACTION AND ENCAPSULATION Computer programs can be very complex, perhaps the most complicated artifact.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
11 Chapter 11 Object-Oriented Databases Database Systems: Design, Implementation, and Management 4th Edition Peter Rob & Carlos Coronel.
Inheritance Building one object from another. Background Object-oriented programming is normally described has offering three capabilities Encapsulation:
Basic OOP Concepts and Terms. In this class, we will cover: Objects and examples of different object types Classes and how they relate to objects Object.
CSE 341, S. Tanimoto Java brief review - 1 Java Brief Review Java’s strengths Object-oriented terminology Inheritance Interfaces An example with inheritance.
Learners Support Publications Object Oriented Programming.
CSC 131 Fall 2006 Lecture # 6 Object-Oriented Concepts.
Abstraction ADTs, Information Hiding and Encapsulation.
Programming Paradigms Lecturer Hamza Azeem. What is PP ? Revision of Programming concepts learned in CPLB Learning how to perform “Object-Oriented Programming”
Microsoft Visual Basic 2008 CHAPTER ELEVEN Multiple Classes and Inheritance.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
CS451 - Lecture 2 1 CS451 Lecture 2: Introduction to Object Orientation Yugi Lee STB #555 (816) * Acknowledgement:
Basic Concepts of Object Orientation Object-Oriented Analysis CIM2566 Bavy LI.
OOP Review CS 124.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Basic Concepts of OOP.  Object-Oriented Programming (OOP) is a type of programming added to php5 that makes building complex, modular and reusable web.
Object orientation and Packaging in Java Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify.
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
OOPS CONCEPT.  OOPS  Benefits of OOPs  OOPs Principles  Class  Object Objectives.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
Chapter 11 An introduction to object-oriented design.
CPS120: Introduction to Computer Science Lecture 16A Object-Oriented Concepts.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
 The Object Oriented concepts was evolved for solving complex problems. Object- oriented software development started in the 1980s. Object-oriented design.
Section 2.1: Programming paradigms
OOP: Encapsulation &Abstraction
Reuse Separate classes could be developed for all the different objects that are needed in each program. However that would be wasteful. Often many functionalities.
Lecture 12 Inheritance.
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
Section 2.1: Programming paradigms
Object-oriented programming principles
3 Fundamentals of Object-Oriented Programming
Object Oriented Analysis and Design
Advanced Java Programming
Object-Oriented Programming
Inheritance and Polymorphism
Object-Oriented PHP (1)
Final and Abstract Classes
CSG2H3 Object Oriented Programming
Presentation transcript:

Object Oriented Programming B.Sc. Digital MediaMultimedia Studio

Agenda Procedural Programming v OOP Software Objects Classes and Methods The Object Oriented Paradigm

Object Oriented Programming Object-Oriented Programming is a way of describing and structuring software systems that features objects that contain functionality and data Early program structure techniques kept program functionality and data separate - so called “procedural programming”

Procedural Programming 10 readln(sum) 20 sum = sum + x 30 writeln(“The answer is” ), sum). 60 GOSUB readln(answer). 300 return

Object Oriented Programming OOP places the data and functionality inside a software object - the data is said to be encapsulated within the object Software object data and functionality

Object Oriented Programming Software objects communicate with other software objects to carry out the overall function of a software system by sending messages to each other Software object data and functionality Software object data and functionality

Transport System To model vehicles and drivers as an OOP software system think about the various objects, properties and functions of such a system: Vehicles - Type, Make, Model, Value, Registration Number Drivers - Name, Age, Date of Birth, License Type

Transport System: Vehicle Object: Vehicles Properties (attributes) Type Make Model Value Registration Number Functions (methods) Create an object of type Vehicle Set the Make of vehicle Get the make of vehilce Set the value of the vehicle

Transport System: Driver Object: Driver Properties (attributes) Name Date of Birth License Type Value Functions (methods) Create an object of type Driver Set the Name of a driver Get the name of a driver Set the type of licence Get the type of licence

Vehicle Object Vehicle Properties: Make Model Registration No. Value Set Make Get Make Set Registration No. Get Registration No. Functions (methods) to communicate with a Vehicle object

Driver Object Driver Properties: Name Date of Birth License Type Set Name Get Name Set Date of Birth Get Date of Birth Functions (methods) to communicate with a Driver object Set Licence Type Get License Type

Vehicle Object Vehicle Properties: Make Model Registration No. Value Set Make Get Make Set Registration No. Various Behavior Public Visibility (Interface to Object)

Encapsulation (Data Hiding) Vehicle Set Make Get Make Set Registration No. Various Behavior Known and consistent public interface Internal workings of class hidden users of the class access functionality via the public interface Owners of the class may change internal representations inside the class but maintain known public interface for users

Object Oriented Programming Features Classes are templates for objects, classes define properties and methods which dictate the state and behavior of the resulting software object Data and related functions are contained within the same object space - encapsulation (data hiding) Classes can be extended by creating subclasses which have similar properties and behaviors - inheritance Inherited behaviors can be modified (overridden) to change the way an object responds to common messages- polymorphism These three characteristics of OOP are often referred to as the “Object Oriented Paradigm”

Class Structures and Methods

Class Definition for a Vehicle (.as) public class Vehicle { // constructor // public function Vehicle(){ } // end constructor // properties // var regNo:String; var make:String; var model:String; var saleValue:int;

Set Method Definition (.as) // set the registration number // public function setRegNumber(aRegNumber:String):void { this.regNo = aRegNumber; } // end setRegNumber

Get Method Definition (.as) // get the registration number // public function getRegNumber():String { var aRegNumber:String; aRegNumber = this.regNo; return aRegNumber; } // end getRegNumber

ActionScript 3.0 Implementation Details (.fla) var aCar:Vehicle = new Vehicle(); var reg:String; var make:String; aCar.setRegNumber("BKD 1"); aCar.setMake("Ferrari"); // verify it works make = aCar.getMake(); reg = aCar.getRegNumber(); trace(make); trace(reg);

Inheritance (subclassing) A class can be extended by creating a subclass based on the class. The subclass will inherit the properties and behavior of the superclass from which it is based Additional properties and behavior can be added to the subclass B.Sc. Multimedia ComputingMultimedia Authoring

Transport System Subclass Example LeaseVehicle SuperclassVehicle Subclass

Transport System: Vehicle Object: Vehicles Properties (attributes) Type Make Model Value Registration Number B.Sc. Multimedia ComputingMultimedia Authoring Functions (methods) Create an object of type Vehicle Set the Make of vehicle Get the make of vehicle Set the value of the vehicle Any subclass of Vehicle will inherit all the properties and methods of the Vehicle class

Transport System: Vehicle and LeaseVehicle Object: Vehicles Properties (attributes) Type Make Model Value Registration Number Functions (methods) Create an object of type Vehicle Set the Make of vehicle Get the make of vehicle Set the value of the vehicle Functions Create an object of type LeaseVehicle Set the leaseValue Get the leaseValue Set the leaseDate Get the LeaseDate Subclass LeaseVehicle Properties LeaseValue LeaseDate

Class Definition for LeaseVehicle public class LeaseVehicle extends Vehicle { // constructor // public function LeaseVehicle(){ this.make = “Maserati”; this.regNo= “1 BKD”; } // end constructor // properties // var leaseValue:int; var leaseDate:Date;

Class Definition for LeaseVehicle public class LeaseVehicle extends Vehicle { // constructor // public function LeaseVehicle(){ this.regNo = "1 BKD"; this.make = "Maserati"; } // end constructor // properties // var leaseValue:int; var leaseDate:Date; }

Inherited Set Definitions // not required as inherited from superclass // public function setRegNumber(aRegNumber:String):void { this.regNo = aRegNumber; } // end setRegNumber

Inherited Get Definitions // not required as inherited from superclass // public function getRegNumber():String { var aRegNumber:String; aRegNumber = this.regNo; return aRegNumber; } // end getRegNumber

ActionScript 3.0 Implementation Details // instantiate a new LeaseVehicle object var aLeaseCar:LeaseVehicle = new LeaseVehicle(); //local variables var reg:String; var make:String; // set the local variables by calling the inherited methods // from the Vehicle class make = aLeaseCar.getMake(); reg = aLeaseCar.getRegNumber(); // verify the data trace(make); trace(reg);

Overriding Methods Subclassed methods can be overridden to modify their behavior for a given software design requirement that most reflects the inherited behaviour. The Vehicle class has a getSaleValue method which is not suited for a LeaseVehicle - lease vehicles are sold at the end of the lease period for a well below market value. Thus the getSaleValue method in the LeaseVehicle class could be overridden to reflect this modified behaviour.

Vehicle Class getSaleValue Method public method getSaleValue():int{ var price:int; price = 12000; return price };

Override Method for LeaseVehicle Class override public method getSaleValue():int{ var price:int; price = ( discount); return price };

Override Method for LeaseVehicle Class salePrice = aVehicle.getSaleValue() Gets the sale price for a Vehicle salePrice = aLeaseVehicle.getSaleValue() Gets the sale price – discount value for a Lease Vehicle as the getSaleValue method has been overidden (modified) in the LeaseVehicle class

Access Modifiers Access to an object’s properties and methods by other objects I controlled by using an access modifier - public, private, or protected public - available to all code private- available only within the same class protected - available within the same class and subclasses

Summary Encapsulation - data hiding Inheritance - subclassing Polymorphism - overriding behaviors Access Modifiers - controlling access to objects and methods