Theory *OOP Charachteristic*

Slides:



Advertisements
Similar presentations
Department of Computer Engineering Faculty of Engineering, Prince of Songkla University 1 5 – Abstract Data Types.
Advertisements

Object Oriented Programming in Java. Object Oriented Programming Concepts in Java Object oriented Programming is a paradigm or organizing principle for.
Module 8 “Polymorphism and Inheritance”. Outline Understanding Inheritance Inheritance Diagrams Constructors in Derived Classes Type Compatibility Polymorphism.
Encapsulation, Inheritance & Interfaces CSE 115 Spring 2006 February 27, March 1 & 3, 2006.
1 Evan Korth New York University Inheritance and Polymorphism Professor Evan Korth New York University.
Object-oriented Programming Concepts
1 Evan Korth New York University Inheritance and Polymorphism Professor Evan Korth New York University.
Chapter 7 - Generalization/Specialization and Inheritance1 Chapter 7 Generalization/Specialization and Inheritance.
1 Pertemuan 6 Object Oriented Programming Matakuliah: T0053/Web Programming Tahun: 2006 Versi: 2.
Object-Oriented Programming Concepts
Programming Languages and Paradigms Object-Oriented Programming.
“is a”  Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class.
Lecture 3 Casting Abstract Classes and Methods Interfaces.
Chapter 4 Objects and Classes.
CSM-Java Programming-I Spring,2005 Objects and Classes Overview Lesson - 1.
OVERRIDING/OVERLOADING Srinivas. EXAM OBJECTIVES  Given a code example, determine if a method is correctly overriding or overloading another method,
Object Oriented Programming: Java Edition By: Samuel Robinson.
Guided Notes Ch. 9 ADT and Modules Ch. 10 Object-Oriented Programming PHP support for OOP and Assignment 4 Term project proposal C++ and Java Designer.
Inheritance - Polymorphism ITI 1121 Nour El Kadri.
Object-Oriented Design CSC 212. Announcements This course is speeding up and we are starting new material. Please see me if you feel this is going too.
Inheritance The Basics in Java. Definition  A class that is derived from another class is called a subclass (also a derived class, extended class, or.
Inheritance Chapter 10 Programs built from objects/instances of classes An O.O. approach – build on earlier work. Use classes in library and ones you have.
Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 9 - Object-Oriented Programming: Inheritance Outline 9.1 Introduction 9.2 Superclasses and Subclasses.
Programming Paradigms Lecturer Hamza Azeem. What is PP ? Revision of Programming concepts learned in CPLB Learning how to perform “Object-Oriented Programming”
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
© 2007 Lawrenceville Press Slide 1 Chapter 8 Objects  A variable of a data type that is a class. Also called an instance of a class.  Stores data  Can.
Programming With Java ICS201 University Of Ha’il1 Chapter 7 Inheritance.
Coming up: Inheritance
© 2007 Lawrenceville Press Slide 1 Chapter 9 Inheritance  One class is an extension of another.  Allows a class to define a specialized type of an existing.
Access Specifier. Anything declared public can be accessed from anywhere. Anything declared private cannot be seen outside of its class. When a member.
AD Lecture #1 Object Oriented Programming Three Main Principles 1 Inheritance Encapsulation Polymorphism.
By : Robert Apeldorn. What is OOP?  Object-oriented programming is a programming paradigm that uses “objects” to design applications and computer programs.
12-CRS-0106 REVISED 8 FEB 2013 CSG2H3 Object Oriented Programming.
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
Testing in OO Environment The reasons for testing is not any different for any of the design and implementation methodologies, including OO methodology.
COMPUTER SCIENCE & TECHNOLOGY DEGREE PROGRAMME FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UVA WELLASSA ‏ Properties of Object Oriented Programming.
Comp1004: Inheritance II Polymorphism. Coming up Inheritance Reminder Overriding methods – Overriding and substitution Dynamic Binding Polymorphism –
Inheritance a subclass extends the functionality of a superclass a subclass inherits all the functionality of a superclass don't reinvent the wheel – "stand.
 The Object Oriented concepts was evolved for solving complex problems. Object- oriented software development started in the 1980s. Object-oriented design.
Programming With Java ICS201 University Of Ha’il1 ICS 201 Introduction to Computer Science Inheritance.
Object Oriented Programming (OOP)
Object-Oriented Programming
Web Design & Development Lecture 9
What is an Object Objects are key to understanding object-oriented technology. An object can be considered a "thing" that can perform a set of related.
JAVA By Waqas.
Inheritance ITI1121 Nour El Kadri.
One class is an extension of another.
Interface.
IST311 Advanced Issues in OOP: Inheritance and Polymorphism
Can perform actions and provide communication
One class is an extension of another.
Can perform actions and provide communication
Interface.
OBJECT ORIENTED PROGRAMMING II LECTURE 8 GEORGE KOUTSOGIANNAKIS
Object-Oriented Programming
Can perform actions and provide communication
Inheritance Inheritance is a fundamental Object Oriented concept
Chapter 14 Abstract Classes and Interfaces
By Rajanikanth B OOP Concepts By Rajanikanth B
CIS 199 Final Review.
Introducing Java.
Final and Abstract Classes
Object-Oriented Programming
Chapter 11 Inheritance and Encapsulation and Polymorphism
Topics OOP Review Inheritance Review Abstract Classes
CSG2H3 Object Oriented Programming
Presentation transcript:

Theory *OOP Charachteristic* Abstraction, encapsulation, inheritance, polymorphism

Abstraction The way we look at a system in a simpler form, ie as a collection of subsystems (object) interacting. Car is a collection of ignition system, steering system, braking system . Tools to abstract something is class. Object is modularity. Object can be written and maintained separate (independent) from another object.

Encapsulation Mechanism hide a process and the data in the system to avoid interference, and simplify the use of the process itself. Stick transmission (gear) on the car. The button on / off (temperature setting) on the air conditioner. Class access levels (public, protected, private) is the implementation of the concept of encapsulation. Data encapsulation can be done by: declare instance variables as private. methods that are declared public to access these variables.

private void createPoint(x, y){ } public void createLine(tA, tB){ Class Circle{ void createCircle(){ } for(){ Line.createLine() class Line{ private void createPoint(x, y){ } public void createLine(tA, tB){

Encapsulation and Access Modifier In the Same Class Same Package In SubClass In Another Package private    without signs (empty) protected public   

Encapsulation Data encapsulation can also be done by: declare instance variables as private. methods that are declared public to access these variables.

Bicycle.java public class Bicycle{ int gir; void setGir(int increaseGir) { gir = gir + increaseGir; } int getGir() { return gir;

BicycleDemo.java public class BicycleDemo{ public static void main(String[] args) { Bicycle mybike = new Bicycle(); mybike.setGir(1); /* Variabel bisa diubah atau tidak sengaja diubah. Hal ini berbahaya dan sering menimbulkan bug. Berikan access modifier private pada instance variable */ mybike.gir = 3; System.out.println(“Gir today is : “ + mybike.getGir()); }

Bicycle.java public class Bicycle{ private int gir; // access modifier private in instance variable void setGir(int increaseGir) { gir = gir + increaseGir; } int getGir() { return gir;

Inheritance A class can inherit attributes (variable) and methods to another class (subclass), as well as forming a class hierarchy. Important for Reusability. Java Keyword: Extends

Bicycle.java public class Bicycle{ private int gir; void setGir(int increaseGir) { gir = gir + increaseGir; } int getGir() { return gir;

MountainBike Class Inherits Bicycle Class public class MountainBike extends Bicycle{ private int saddle; void setSaddle (int total) { saddle = getGir() - total; } int getSaddle(){ return saddle; public class MountainBikeDemo { public static void main(String[] args) { MountainBike mb = new MountainBike(); mb.setGir(3); System.out.println(mb.getGir()); mb.setSaddle(1); System.out.println(mb.getSaddle()); } MountainBike.java MountainBikeDemo.java

Exercise: Inheritance Mathematics Make AdvancedMathematics class which is inherit from class Mathematics Add method modulo (int a, int b) that calculates the modulo of a and b. The modulo operator is %. Create a class that calls the method AdvancedMathematicDemo that is accretion(+), multiplication (*) and modulo (%).

Polymorphism The ability to treat objects that have behavior (shape) different. Implementation of the concept of polymorphism: Overloading: The ability to use the same name for several method that different parameters (type and/or number). Overriding: The ability of a subclass to override a superclass method, that is by using the same name and parameters on method.

Polymorphism – Overloading class Car { String color; int productionYear; public Car(String color, int productionYear){ this.color = color; this.productionYear = productionYear; } public Car(){ void info(){ System.out.println(“Color: " + color); System.out.println(“Year: " + productionYear); public class CarConstructors{ public static void main(String[] args){ Car mycar = new Car(“Red”, 2014); mycar.info(); Car yourcar = new Car(); yourcar.info(); } Output Programs : Color: Red Year : 2014 Color: null Year: 0

Polymorphism – Overloading class Circle{ void createCircle(){ } void createCircle(int diameter){ ... void createCircle(double diameter){ void createCircle(int diameter, int x, int y){ ... void createCircle(int diameter, int x, int y, int color, String circleName){ ...

Polymorphism - Overriding public class Bicycle{ private int gir; void setGir(int increaseGir) { gir = gir + increaseGir; } int getGir() { return gir;

Polymorphism - Overriding public class MountainBike extends Bicycle{ void setGir(int increaseGir) { super.setGir(increaseGir); gir = 2*getGir(); } public class MountainBikeDemo { public static void main(String[] args) { MountainBike mb = new MountainBike(); mb.setGir(2); System.out.println(mb.getGir()); mb.setGir(3); } MountainBike.java MountainBikeDemo.java

Exercise: Overloading in Mathematics Develop Mathematic class, AdvancedMathematic and MathematicDemo. Perform overloading the existing method (accretion[+], subtraction[-], multiplication[*], division[/], modulo[%]) Add a new method with data type double and has 3 parameters. Test class with parameters MathematicDemo fractions: 12.5, 28.7, 14.2 For example: accretion(12.5, 28.7, 14.2) accretion(12, 28, 14) accretion(23, 34) accretion(3.4, 4.9)

Mathematic.java public class Mathematic{ void accretion(int a, int b){ int total= a + b; System.out.println(“Result:” + total); } void accretion(double a, double b, double c){ double total = a + b + c; ...

Thankyou . . .

Reference http://romisatriawahono.net/lectures/ Object First With Java, Fifth edition, David J. Barnes & Michael Kölling, Prentice Hall / Pearson Education, 2012. The JavaTM Tutorial, http://docs.oracle.com/javase/tutorial/java/nutsandbolts/, Oracle, 1995-2014. Java SE Tutorial, http://www.oracle.com/technetwork/java/javase/downloads/java- se-7-tutorial-2012-02-28-1536013.html, Oracle, 2014. SCJP Sun Certified Programmer for JavaTM 6 Study Guide Exam (310- 065), Kathy Sierra & Bert Bates, Mc Graw Hill, 2008.