Class Structures and Methods B.Sc. Multimedia ComputingMultimedia Authoring.

Slides:



Advertisements
Similar presentations
Final and Abstract Classes
Advertisements

Abteilung für Telekooperation Softwareentwicklung 2 UE SE2UE_ Vererbung (Inheritance)
General OO Concepts Objectives For Today: Discuss the benefits of OO Programming Inheritance and Aggregation Abstract Classes Encapsulation Introduce Visual.
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.
Object-Oriented Application Development Using VB.NET 1 Chapter 8 Understanding Inheritance and Interfaces.
Inheritance Java permits you to use your user defined classes to create programs using inheritance.
ITEC200 – Week03 Inheritance and Class Hierarchies.
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 8.1 – 8.5.
1 Evan Korth New York University Inheritance and Polymorphism Professor Evan Korth New York University.
Object-oriented Programming Concepts
8.1 Classes & Inheritance Inheritance Objects are created to model ‘things’ Sometimes, ‘things’ may be different, but still have many attributes.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Object Oriented Programming B.Sc. Multimedia ComputingMultimedia Authoring.
Chapter 7 - Generalization/Specialization and Inheritance1 Chapter 7 Generalization/Specialization and Inheritance.
Inheritance. © 2004 Pearson Addison-Wesley. All rights reserved 8-2 Inheritance Inheritance is a fundamental object-oriented design technique used to.
Inheritance using Java
UFCEUS-20-2 : Web Programming Lecture 5 : Object Oriented PHP (1)
OOP (Object Oriented Programming with AS3) Flash ActionScript 3.0 Introduction to Thomas Lövgren, Flash developer Introduction.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
OOPs Object oriented programming. Based on ADT principles  Representation of type and operations in a single unit  Available for other units to create.
CSM-Java Programming-I Spring,2005 Objects and Classes Overview Lesson - 1.
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.
Features of Object Oriented Programming Lec.4. ABSTRACTION AND ENCAPSULATION Computer programs can be very complex, perhaps the most complicated artifact.
CS200 Algorithms and Data StructuresColorado State University Part 4. Advanced Java Topics Instructor: Sangmi Pallickara
Object Oriented Programming Concepts. Object Oriented Programming Type of programming whereby the programmer defines the data types of a data structure.
Object Oriented Programming B.Sc. Digital MediaMultimedia Studio.
Encapsulation, Inheritance & Polymorphism. OOP Properties Encapsulation ­The process of creating programs so that information within a class is not accessible.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
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”
8. Inheritance “Is-a” Relationship. Topics Creating Subclasses Overriding Methods Class Hierarchies Abstract Class Inheritance and GUIs The Timer Class.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
OOPs Object oriented programming. Abstract data types  Representationof type and operations in a single unit  Available for other units to create variables.
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Classes, Interfaces and Packages
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.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
SUBCLASSES - JAVA. The Purpose of Subclasses Class Farm String getOwner() void setOwner(String s) int getSize() void setSize(int s) Class DairyFarm String.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
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.
Final and Abstract Classes
Inheritance and Polymorphism
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
Object-oriented programming principles
3 Fundamentals of Object-Oriented Programming
Object Oriented Analysis and Design
Advanced Java Programming
Testing with OO OO has several key concepts:
Object-Oriented Programming
Inheritance and Polymorphism
Object Oriented Analysis and Design
Object-Oriented PHP (1)
Final and Abstract Classes
Chapter 11 Inheritance and Encapsulation and Polymorphism
Extending Classes Through Inheritance
CSG2H3 Object Oriented Programming
Presentation transcript:

Class Structures and Methods B.Sc. Multimedia ComputingMultimedia Authoring

Agenda Encapsulation Inheritance Polymorphism Extending Classes and Overriding Methods Access Modifiers B.Sc. Multimedia ComputingMultimedia Authoring

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” B.Sc. Multimedia ComputingMultimedia Authoring

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

Encapsulation (Data Hiding) B.Sc. Multimedia ComputingMultimedia Authoring 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

Transport System Subclass Example B.Sc. Multimedia ComputingMultimedia Authoring LeaseVehicle SuperclassVehicle Subclass

Inheritance (subclassing) A class can be extended by creating a subclass bases 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: 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 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 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 B.Sc. Multimedia ComputingMultimedia Authoring 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 B.Sc. Multimedia ComputingMultimedia Authoring package uk.ac.uwe.multimedia.transport{ // import Vehcicle class to extend import uk.ac.uwe.multimedia.transport.Vehicle; // base this class on the Vehicle class public class LeaseVehicle extends Vehicle { // constructor // public function LeaseVehicle(){ //super(); this.regNo = "1 BKD"; this.make = "Maserati"; } // end constructor // properties // var leaseValue:int; var leaseDate:Date; }

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

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

Subclass Instantiation and Method References B.Sc. Multimedia ComputingMultimedia Authoring var aLeaseCar:LeaseVehicle = new LeaseVehicle(); var reg:String; var make:String; // aLeaseCar.setRegNumber("BKD 2"); already set // aLeaseCar.setMake(”Maserati"); already set // via super() in Vehicle class construtor make = aLeaseCar.getMake(); reg = aLeaseCar.getRegNumber();

ActionScript 3.0 Implementation Details B.Sc. Multimedia ComputingMultimedia Authoring //import the class via the folder structure import uk.ac.uwe.multimedia.transport.LeaseVehicle; // 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);

Access Modifiers Access to an object’s properties and methods by other objects is 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 B.Sc. Multimedia ComputingMultimedia Authoring

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. B.Sc. Multimedia ComputingMultimedia Authoring

Vehicle Class getSaleValue Method public method getSaleValue():int{ var price:int; price = 12000; return price }; B.Sc. Multimedia ComputingMultimedia Authoring

Overriding Methods B.Sc. Multimedia ComputingMultimedia Authoring override public method getSaleValue():int{ var price:int; price = ( discount); return price };

Summary Encapsulation - data hiding Inheritance - subclassing Polymorphism - overriding behaviors Access Modifiers - controlling access to objects and methods B.Sc. Multimedia ComputingMultimedia Authoring