Evolution of Programming Languages Object-Oriented Paradigm II.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming
Advertisements

Understand and appreciate Object Oriented Programming (OOP) Objects are self-contained modules or subroutines that contain data as well as the functions.
Department of Computer Engineering Faculty of Engineering, Prince of Songkla University 1 5 – Abstract Data Types.
Lab 2: Polymorphism zOne Name, Many Purposes zTwo forms: yFunction Overloading yOperator Overloading.
C++ Classes & Data Abstraction
Module 8 “Polymorphism and Inheritance”. Outline Understanding Inheritance Inheritance Diagrams Constructors in Derived Classes Type Compatibility Polymorphism.
OBJECT ORIENTED PROGRAMMING (OOP) IN PYTHON David Moodie.
1 Chapter 6: Extending classes and Inheritance. 2 Basics of Inheritance One of the basic objectives of Inheritance is code reuse If you want to extend.
Inheritance Inheritance Reserved word protected Reserved word super
 In inheritance the child (subclass) chooses its parent (superclass)  Remember - only public or “protected” methods and variables are inherited  Should.
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 8.1 – 8.5.
COMP171 Data Structure & Algorithm Tutorial 1 TA: M.Y.Chan.
1 Programming Week 2 James King 12 August Creating Instances of Objects Basic Java Language Section.
Chapter 3 Data Abstraction: The Walls. © 2005 Pearson Addison-Wesley. All rights reserved3-2 Abstract Data Types Modularity –Keeps the complexity of a.
C# Programming: From Problem Analysis to Program Design1 Creating Your Own Classes C# Programming: From Problem Analysis to Program Design 3rd Edition.
16/22/2015 2:54 PM6/22/2015 2:54 PM6/22/2015 2:54 PMObject-Oriented Development Concept originated with simulating objects and their interactions. Adapted.
Data Abstraction and Object- Oriented Programming CS351 – Programming Paradigms.
COMP 14: Writing Classes June 6, 2000 Nick Vallidis.
C++ fundamentals.
OBJECT ORIENTED PROGRAMMING IN C++ LECTURE
Classes in C++ Bryce Boe 2012/08/15 CS32, Summer 2012 B.
Object Oriented Software Development
Inheritance using Java
Classes Mark Hennessy Dept. Computer Science NUI Maynooth C++ Workshop 18 th – 22 nd Spetember 2006.
Object Oriented Programming Development
C++ Code Analysis: an Open Architecture for the Verification of Coding Rules Paolo Tonella ITC-irst, Centro per la Ricerca Scientifica e Tecnologica
Intro to OOP with Java, C. Thomas Wu
School of Computer Science & Information Technology G6DICP - Lecture 22 The Theory of Object Oriented Programming.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
1 Practical test tomorrow zWill involve writing a simple class zinstantiating objects zother C++ constructs as practised in the lab sheets to date zinheritance.
RIT Computer Science Dept. Goals l Inheritance l Modifiers: private, public, protected l Polymorphism.
1 Object Oriented Programming Development - Week7 z Rob Manton z z Room D104.
1 Object Oriented Programming Development - Week 3 z By: Marc Conrad University of Luton z z Room: D104.
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.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
1 CS2136: Paradigms of Computation Class 09: Object-Oriented Programming Copyright 2001, 2002, 2003, Michael J. Ciaraldi and David Finkel.
1 What is the purpose of Inheritance? zSpecialisation Extending the functionality of an existing class zGeneralisation sharing commonality between two.
Object Oriented Software Development
Simple Classes. ADTs A specification for a real world data item –defines types and valid ranges –defines valid operations on the data. Specification is.
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Component 4: Introduction to Information and Computer Science Unit 5: Overview of Programming Languages, Including Basic Programming Concepts Lecture 5.
© 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.
Conditionals Opening Discussion zWhat did we talk about last class? zDo you have any questions about the assignment? zPass by value limitations.
CSCI-383 Object-Oriented Programming & Design Lecture 24.
Classes, Interfaces and Packages
Methods Awesomeness!!!. Methods Methods give a name to a section of code Methods give a name to a section of code Methods have a number of important uses.
AP Java Ch. 4 Review Question 1  Java methods can return only primitive types (int, double, boolean, etc).
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
1 Enhanced Class Design Introduction zWe now examine several features of class design and organization that can improve reusability and system elegance.
Inheritance and Virtual Functions Opening Discussion zDo you have any questions about the quiz? zWhat did we talk about last class?
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
Structure A Data structure is a collection of variable which can be same or different types. You can refer to a structure as a single variable, and to.
SUBCLASSES - JAVA. The Purpose of Subclasses Class Farm String getOwner() void setOwner(String s) int getSize() void setSize(int s) Class DairyFarm String.
Software Construction Lab 05 Abstraction, Inheritance, and Polymorphism in Java.
Seventh step for Learning C++ Programming CLASS Declaration Public & Private Constructor & Destructor This pointer Inheritance.
Improving structure with inheritance Main concepts to be covered Inheritance Subtyping Substitution Polymorphic variables © 2017 Pearson Education,
Computer Programming II Lecture 5. Introduction to Object Oriented Programming (OOP) - There are two common programming methods : procedural programming.
Programming what is C++
Concepts of Object Oriented Programming
CS240: Advanced Programming Concepts
An Introduction to Java – Part II
Conditional Statements
Object Oriented Theory I
UNIT I OBJECT ORIENTED PROGRAMMING FUNDAMENTALS
Object-Oriented Programming
CIS 199 Final Review.
Review of Previous Lesson
CPS120: Introduction to Computer Science
Chapter 11 Classes.
Presentation transcript:

Evolution of Programming Languages Object-Oriented Paradigm II

Object-Oriented Programming zIn the game outlined in the previous presentation, we defined a ‘Goodie ’as class goodie{ int personality; int agility; int inteligence; int health; void move( ); void fight( ); void getTreasure( ); };

Object-Oriented Programming zWe may define a ‘Baddie’ as class baddie{ int agility; int health; int aggression; int badType; void move( ); void fight( ); void makeNoise( ); };

Object-Oriented Programming zThe baddie class is very similar to the goodie class. zThe attribute ‘intelligence’ has been removed, and ‘aggression’ and ‘badType’ added. zA ‘makeNoise’ method has also been added.

Object-Oriented Programming zWhy can’t we combine these two classes into one, and create a superclass like ‘character’? zThis class could contain all of the common attributes and methods of the two classes.

Inheritance zSub-classes can inherit all of the attributes and methods from their superclass or parent class. zThis process is called inheritance. zInheritance encourages modularity and robust code.

Example Character GoodieBaddie Mr NiceMiss LovelyMr Wild GrizzlyCrazy

Example zThe C++ declaration of a ‘character’ could be: class character{ int agility; int health; void move( ); void fight( ); };

Example zThe declaration of a goodie now becomes: class goodie: character{ int personality; int intelligence; void getTreasure( ); };

Example zThe declaration of a baddie becomes: class baddie: character{ int aggression; int badType; void makeNoise( ); };

Abstraction zThe process of designing objects by breaking them down into component classes or picking out the common features of objects and procedures is called abstraction. zEach feature can then be dealt with in isolation.

Initialising Attributes zTo initialise the value of an attribute, you need to use a method within the declaration of that class called a constructor method.

Constructor Methods zConstructor methods always have the same name as the class in which they reside. zThis is what tells the compiler that the method is a constructor rather than a normal method.

Constructor Method Examples class character{ int agility; int health; character( ) { agility=health=5; } void move( ); void fight( ); }; class baddie: character{ int aggression; int badType; baddie(int a, int b) { aggression=a; badType=b; } void makeNoise( ); };

Creating the object zThe statement baddie Crazy(3,2) would create a baddie object called Crazy with agility and health values of 5, an aggression value of 3 and a badType value of 2

What next? zWhat if we want to create goodies with a different initial agility and health to a baddie?

What next? zWe have to modify the character class definition to allow this. zWe will also add a constructor to the goodie class that receives all our inputs and passes on the health and agility inputs to the character class.

Modified character class class character{ int agility; int health; character( ) { agility=health=5; } character(int a, int h){ agility = a; health = h; } void move( ); void fight( ); };

Modified goodie class class goodie: character{ int personality; int intelligence; goodie(int a, int h, int p, int I):character(a,h){ personality=p; intelligence=i; } void getTreasure( ); };

Creating the object zThe statement goodie MrNice(4,7,3,8) would create a goodie object called MrNice where agility=4, health=7, personality=3 and intelligence=8.