1 CS4850 Programming Languages Wuwei Shen. 2 Aministrivia Course home page: Reference books: –Programming Languages,

Slides:



Advertisements
Similar presentations
Object-Oriented Programming. 2 An object, similar to a real-world object, is an entity with certain properties, and with the ability to react in certain.
Advertisements

CS 350 – Software Design The Bridge Pattern – Chapter 10 Most powerful pattern so far. Gang of Four Definition: Decouple an abstraction from its implementation.
Inheritance // A simple class hierarchy. // A class for two-dimensional objects. class TwoDShape { double width; double height; void showDim() { System.out.println("Width.
Object-oriented Software Change Dynamic Impact Analysis Lulu Huang and Yeong-Tae Song Dept. of Computer and Information Sciences Towson University Towson,
Object-Oriented Design – Key Concepts Version 1.1 of : added learning objectives CompSci 230 Software Construction.
INTERFACES IN JAVA 1.Java Does not support Multiple Inheritance directly. Multiple inheritance can be achieved in java by the use of interfaces. 2.We need.
Inheritance Lakshmish Ramaswamy. Example A Rectangle class with area method A Circle class with area method Array containing references to circles & rectangles.
5/17/2015 OO Design: Liskov Substitution Principle 1.
Testing and Inheritance What is the relation between the test suite of a superclass and a subclass?
1 CS4850 Programming Languages Wuwei Shen. 2 Aministrivia Course home page: Reference books: –Programming Languages,
More Inheritance and LSP CS340100, NTHU Yoshi. More about Inheritance Reuse? – Q1: 你有沒有程式 ” 砍掉重練 ” 的經驗 ? – Q2: 你有沒有 ” 再造輪子 ” 的經驗 ? class Rectangle – Firstly,
Inheritance. Extending Classes It’s possible to create a class by using another as a starting point  i.e. Start with the original class then add methods,
Typing Issues and LSP Amit Shabtay. March 3rd, 2004 Object Oriented Design Course 2 Typing Static typing Readability (Java vs. Pearl) Catching errors.
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.
1 Introduction to CS Agenda Syllabus Schedule Lecture: the management of complexity.
Typing Issues and LSP David Rabinowitz. March 3rd, 2004 Object Oriented Design Course 2 Typing Static typing Reliability Catching errors early Readability.
1 Topic 4 Inheritance "Question: What is the object oriented way of getting rich? Answer: Inheritance.“
CS 2511 Fall  Abstraction Abstract class Interfaces  Encapsulation Access Specifiers Data Hiding  Inheritance  Polymorphism.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Inheritance and Polymorphism CS351 – Programming Paradigms.
Chapter 11: Inheritance and Polymorphism Java Programming: Program Design Including Data Structures Program Design Including Data Structures.
CS221 - Computer Science II Polymorphism 1 Inheritance "Question: What is the object oriented way of getting rich? Answer: Inheritance.“ “Inheritance is.
CSc 335: Three More OO Design Principles
COMPUTER PROGRAMMING. Introduction to C++ History Merges notions from Smalltalk and notions from C The class concept was borrowed from Simular67 Developed.
WEEK 1 CS 361: ADVANCED DATA STRUCTURES AND ALGORITHMS Dong Si Dept. of Computer Science 1.
UML Basics & Access Modifier
UFCEUS-20-2 : Web Programming Lecture 5 : Object Oriented PHP (1)
Programming Languages and Paradigms Object-Oriented Programming.
1 OO Design Principles Project Group eXtreme Programming Md. Abul Bashar 07/09/2004.
Chapter 15 – Inheritance, Virtual Functions, and Polymorphism
Sadegh Aliakbary Sharif University of Technology Fall 2011.
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
Inheritance CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
More Design. Next Tuesday First draft of architectural design –use cases –class diagrams for major classes with responsibilities –sequence diagrams for.
© 2004 Capgemini - All rights reserved SOLID - OO DESIGN PRINCIPLES Andreas Enbohm, Capgemini.
Class Design III: Advanced Inheritance Additional References “Object-Oriented Software Development Using Java”, Xiaoping Jia, Addison Wesley, 2002 “Core.
Lecture.1: Getting Started With Java Jiang (Jen) ZHENG May 9 th, 2005.
Chapter 10 Inheritance and Polymorphism
Software Design Principles
Testing and Inheritance What is the relation between the test suite of a superclass and a subclass?
MIT AITI 2004 – Lecture 13 Abstract Classes and Interfaces.
Salman Marvasti Sharif University of Technology Winter 2015.
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.
Foundations: Language mechanisms and primitive OO concepts Lecture 1: Classification and Inheritance Michigan State University Spring 2008 E. Kraemer Notes.
CSE 143 Lecture 20 Abstract classes. 2 Circle public class Circle { private double radius; public Circle(double radius) { this.radius = radius; } public.
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
CS1201: Programming Language 2 Classes and objects Inheritance By: Nouf Aljaffan Edited by : Nouf Almunyif.
1. Perspectives on Design Principles – Semantic Invariants and Design Entropy Catalin Tudor 2.
L EC. 07: I NHERITANCE S PRING C ONTENT  Inheritance basics  Member access and inheritance  Constructors and inheritance  Superclass references.
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Abstract Classes Course Lecture Slides 7 June 2010 “None of the abstract.
Java & C++ Comparisons How important are classes and objects?? What mechanisms exist for input and output?? Are references and pointers the same thing??
C# - Inheritance Ashima Wadhwa. Inheritance One of the most important concepts in object- oriented programming is inheritance. Inheritance allows us to.
Test Code Patterns How to design your test code. 2 Testing and Inheritance Should you retest inherited methods? Can you reuse superclass tests for inherited.
1 More About Derived Classes and Inheritance Chapter 9.
Modern Programming Tools And Techniques-I
Inheritance ITI1121 Nour El Kadri.
Inheritance class TwoDShape { private double width;
EECE 310: Software Engineering
Comp Sci 200 Programming I Jim Williams, PhD.
Inheritance "Question: What is the object oriented way of getting rich? Answer: Inheritance.“ “Inheritance is new code that reuses old code. Polymorphism.
CS 200 Creating Classes Jim Williams, PhD.
CS 302 Week 10 Jim Williams.
Week 6 Object-Oriented Programming (2): Polymorphism
CSE 1020:Programming by Delegation
Chapter 11 Inheritance and Polymorphism
CS 200 More Classes Jim Williams, PhD.
CS 200 Creating Classes Jim Williams, PhD.
Object Oriented Design & Analysis
Lecture 8 Object Oriented Programming (OOP)
Computer Science II for Majors
Presentation transcript:

1 CS4850 Programming Languages Wuwei Shen

2 Aministrivia Course home page: Reference books: –Programming Languages, Principles and Paradigms, Second Edition by A. Tucker & R. Noonan Office hours: 3-4pm, or by appointment.

3 Why Take This Course? Consider the following program public class Rectangle { private double width, height; Rectangle(double w, double h) { width = w height = h; } public double area() { return width * height; } public void setWidth(double w) { width = w;} public void setHeight(double h){ height = h;} public double getWidth() { return width; } public double getHeight() { return height;} } ;

4 We will learn another way to define what is a “correct” program. This new way has some good advantages. How we, as a programmer of the language, know the error in a program. So, we will learn

5 Continue Let us consider the following client program public class Rectangle_Client { void static main () { Rectangle r = new Rectangle(2,3); System.out.println(r.area()); Rectangle r1 = new Rectangle(3,4); r = r1; System.out.println(r.area()); } What happens to the object Rectangle(2,3)?

6 So, we will learn The semantics of a program: what is the correct output after you call r.area(); Garbage collection: how garbage objects are automatically collected by the operating system/Java runtime system.

OO Languages Inheritance vs Polymorphism public double totalPrice(Part[] parts) { double total = 0.0; for (int i =0; i < parts.length; i++) total += parts[i].getPrice(); return total; }

8 Next We consider a square object. What is the relationship between a rectangle object and square object? public class Square extends Rectangle { Square(double s) { super(s,s); } public void setWidth(double w) { super.setWidth(w); super.setHeight(w);} public void setHeight(double h){ super.setWidth(h); super.setHeight(h);} }

9 However, When we have the following client code: public class TestRectangle { public static void testLSP(Rectangle r) { r.setWidth(4.0); r.setHeight(5.0); System.out.println(r.area); } } What do you think of this code?

10 Another Example We have Class MySet which has two Method addAll(Vector v) and add(Object o) to add object to myset How can we implement an additional feature: account the number of added objects.

11 So We’ll Revisit OO Concepts We will re-evaluate important OO concepts: –Inheritance, –Polymorphism, –Composition Goal: to make the error-free software easy to write, maintain and test.