General Computer Science for Engineers CISC 106 James Atlas Computer and Information Sciences 11/16/2009.

Slides:



Advertisements
Similar presentations
Object Oriented Programming
Advertisements

SUMMARY: abstract classes and interfaces 1 Make a class abstract so instances of it cannot be created. Make a method abstract so it must be overridden.
OOP: Inheritance By: Lamiaa Said.
Fall 2006AE6382 Design Computing1 Object Oriented Programming in Matlab Intro to Object- Oriented Programming (OOP) An example that creates a ASSET class.
Intro to OOP with Java, C. Thomas Wu Inheritance and Polymorphism
Object–Orientated Design. OOP Design Describe the following: a computer a university Usually the most natural way to describe a task is to list the entities.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Inheritance and Polymorphism.
L3-1-S1 OO Concepts © M.E. Fayad SJSU -- CMPE Software System Engineering Dr. M.E. Fayad, Professor Computer Engineering Department, Room.
CSCI 143 OOP – Inheritance 1. What is Inheritance? A form of software reuse Create a new class from an existing class – Absorb existing class data and.
CS 106 Introduction to Computer Science I 11 / 19 / 2007 Instructor: Michael Eckmann.
General Computer Science for Engineers CISC 106 James Atlas Computer and Information Sciences 11/13/2009.
General Computer Science for Engineers CISC 106 James Atlas Computer and Information Sciences 10/30/2009.
Chapter 10 Classes Continued
Using Jeroo To Teach Object-Oriented Concepts By Christian Digout.
UFCEUS-20-2 : Web Programming Lecture 5 : Object Oriented PHP (1)
Chapter 6 Class Inheritance F Superclasses and Subclasses F Keywords: super F Overriding methods F The Object Class F Modifiers: protected, final and abstract.
Overview of Previous Lesson(s) Over View  OOP  A class is a data type that you define to suit customized application requirements.  A class can be.
Inheritance and Class Hierarchies Ellen Walker CPSC 201 Data Structures Hiram College.
Object-Oriented Programming (OOP) Lecture No. 3. Abstraction ► Abstraction is a way to cope with complexity. ► Principle of abstraction: “Capture only.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 11 Inheritance.
CS305j Introduction to Computing Inheritance and Polymorphism 1 Topic 26 Introduction to Inheritance and Polymorphism "One purpose of CRC cards [a design.
General Computer Science for Engineers CISC 106 Lecture 11 James Atlas Computer and Information Sciences 07/27/2009.
Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.
Inheritence Put classes into a hierarchy derive a new class based on an existing class with modifications or extensions. Avoiding duplication and redundancy.
Inheritance Building one object from another. Background Object-oriented programming is normally described has offering three capabilities Encapsulation:
Chapter 5: Ball Worlds Features 2 classes, constant data fields, constructors, extension through inheritance, graphics.
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.
Ch. 2 Discussion Head First Java. Big Idea Differene between a class and an object What benefit object-oriented programming gives you. Read “Chair Wars”
Programming Paradigms Lecturer Hamza Azeem. What is PP ? Revision of Programming concepts learned in CPLB Learning how to perform “Object-Oriented Programming”
CSCI-383 Object-Oriented Programming & Design Lecture 10.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Sadegh Aliakbary Sharif University of Technology Spring 2011.
Copyright © 2006 Pearson Addison-Wesley. All rights reserved Learning Objectives  Inheritance  Virtual Function.
© 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.
Object Oriented Programming
Chapter 7: Class Inheritance F Superclasses and Subclasses F Keywords: super and this F Overriding methods F The Object Class F Modifiers: protected, final.
EE 422C Interfaces Day 5. 2 Announcements SVN has Project 2. –Partly due next week. –SVN update to get it in your repository. See Piazza for Grocery List.
1 Unified Modeling Language, Version 2.0 Chapter 2.
Modeling the Static Structure: Relationships ©SoftMoore ConsultingSlide 1.
Interfaces F What is an Interface? F Creating an Interface F Implementing an Interface F What is Marker Interface?
Object-Oriented Programming (OOP) Lecture No. 4 Downloaded From:
© 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.
Lecture 2: Review of Object Orientation. © Lethbridge/La ganière 2005 Chapter 2: Review of Object Orientation What is Object Orientation? Procedural.
1 / 71 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 4 Programming Fundamentals using Java 1.
1 Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
1 Object-Oriented Programming Inheritance. 2 Superclasses and Subclasses Superclasses and Subclasses  Superclasses and subclasses Object of one class.
Object-Oriented Programming: Inheritance and Polymorphism.
Class Diagram Lecture # 1. Class diagram A Class Diagram is a diagram describing the structure of a system shows the system's classes Attributes operations.
Object-Oriented Programming: Polymorphism Chapter 10.
CSC241 Object-Oriented Programming (OOP) Lecture No. 2.
 2002 Prentice Hall. All rights reserved. Page 1 Inheritance: Object-Oriented Programming Outline 9.1 Introduction 9.2 Superclasses and Subclasses 9.3.
1 C++ Classes & Object Oriented Programming Overview & Terminology.
Sections Inheritance and Abstract Classes
Python First Edition STARTING OUT WITH Chapter 10 Inheritance
Systems Analysis and Design With UML 2
One class is an extension of another.
Computing with C# and the .NET Framework
Road Map Inheritance Class hierarchy Overriding methods Constructors
One class is an extension of another.
Week 6 Object-Oriented Programming (2): Polymorphism
Inheritance in Graphics
Chapter 14 Abstract Classes and Interfaces
An Example of Inheritance
Object Oriented Analysis and Design
Object-Oriented PHP (1)
SE-1021 Software Engineering II
Decorator Pattern.
Chapter 11 Inheritance and Polymorphism
2D Shapes Rectangle Circle Triangle Rectangle. What shape is the door? Rectangle.
Presentation transcript:

General Computer Science for Engineers CISC 106 James Atlas Computer and Information Sciences 11/16/2009

James Atlas Overview Review Review  Inheritance  Cell Arrays Polymorphism Polymorphism  What is it?  Why use it?  How does it work in Matlab?

James Atlas Inheritance The is a relationship The is a relationship Inheritance Hierarchy Inheritance Hierarchy  state (properties)  behavior (methods) Superclass Superclass Subclass Subclass Animal ReptileBird

James Atlas Cell Arrays Normal array Normal array zeros(1,5) is 5 doubles [ ] is 4 doubles Cell array Cell array { } is 4 cells, each with a 1x1 array of double values inside

James Atlas What is a cell? A cell is like a window into a room, and inside the room can be data of any size A cell is like a window into a room, and inside the room can be data of any size A cell array is like a hallway with many doors A cell array is like a hallway with many doors Student age=19 name=‘Joe’ credits=78 ‘hello’ normal arraycell array

James Atlas Polymorphism: What is It?

James Atlas Polymorphism: What is It? One name, many forms One name, many forms  Capability to perform different actions based on the object instance

James Atlas Polymorphism: What is It? One name, many forms One name, many forms  Capability to perform different actions based on the object instance Each band member is a Musician Each band member is a Musician  We could tell all band members to Play  Play for a drummer would perform a different action than Play for a guitarist

James Atlas Polymorphism: Why use it? Easily extensible systems Easily extensible systems  Add new features with low impact on system

James Atlas Polymorphism: Why use it? Easily extensible systems Easily extensible systems  Add new features with low impact on system For example, we are hosting American Idol for Musicians For example, we are hosting American Idol for Musicians  In Season 1 we have guitarists, drummers, and pianists  In Season 2 we add keyboardists, trumpeters and bagpipers

James Atlas Polymorphism: Why use it? Easily extensible systems Easily extensible systems  Add new features with low impact on system For example, we are hosting American Idol for Musicians For example, we are hosting American Idol for Musicians  In Season 1 we have guitarists, drummers, and pianists  In Season 2 we add keyboardists, trumpeters and bagpipers  We don’t need to change the competition format or hosting protocol!

James Atlas Polymorphism: How does it work in Matlab? Overriding Overriding Matlab constructs Matlab constructs  Methods (the behavior)  Classes  Abstract tag

James Atlas Shape.m Class classdef Shape properties properties center_x center_x center_y center_y color color end end methods (Abstract) methods (Abstract) result = area(shape) result = area(shape) handle = draw(shape) handle = draw(shape) end endend

James Atlas Circle.m Class classdef Circle < Shape properties properties radius radius end end methods methods function circle = Circle(center_x, center_y, radius, color) function circle = Circle(center_x, center_y, radius, color) circle.center_x = center_x; circle.center_x = center_x; circle.center_y = center_y; circle.center_y = center_y; circle.radius = radius; circle.radius = radius; circle.color = color; circle.color = color; end end...endend

James Atlas Circle.m Class (cont’) classdef Circle < Shape methods methods... function handle = draw(circle) function handle = draw(circle) handle = rectangle('Position', [... handle = rectangle('Position', [... circle.center_x - circle.radius,... circle.center_x - circle.radius,... circle.center_y - circle.radius,... circle.center_y - circle.radius,... 2 * circle.radius,... 2 * circle.radius,... 2 * circle.radius],... 2 * circle.radius],... 'Curvature', [1 1], 'FaceColor', circle.color); 'Curvature', [1 1], 'FaceColor', circle.color); end end...endend

James Atlas Circle.m Class (cont’) classdef Circle < Shape methods methods... function result = area(circle) function result = area(circle) result = pi * circle.radius * circle.radius; result = pi * circle.radius * circle.radius; end endendend

James Atlas Example: Shape sorter Create rectangle and triangle Create rectangle and triangle Create a cell array of shapes Create a cell array of shapes Update each shape’s x and y center Update each shape’s x and y center Draw shapes and then put them in order by area Draw shapes and then put them in order by area Animate swaps Animate swaps