CS313D: ADVANCED PROGRAMMING LANGUAGE

Similar documents
CS111: PROGRAMMING LANGUAGE II

CS111: PROGRAMMING LANGUAGE II

CS313D: ADVANCED PROGRAMMING LANGUAGE

Lecture Contents CS313D: ADVANCED PROGRAMMING LANGUAGE. What is Inheritance?

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS111: PROGRAMMING LANGUAGE II

Java How to Program, 8/e

Object Oriented Design

Java Programming Lecture 7

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

CS313D: ADVANCED PROGRAMMING LANGUAGE

Object Oriented Programming. Java-Lecture 11 Polymorphism

Object-Oriented Programming

Chapter 5 Object-Oriented Programming

CS111: PROGRAMMING LANGUAGE II

Object Oriented Programming

Exception Handling Introduction. Error-Prevention Tip 13.1 OBJECTIVES

Programming II (CS300)

Object Oriented Programming CS250

CS111: PROGRAMMING LANGUAGE II. Lecture 1: Introduction to classes

Lecture Contents CS313D: ADVANCED PROGRAMMING LANGUAGE

Chapter 10 Classes Continued. Fundamentals of Java

6.Introducing Classes 9. Exceptions

Fundamentals of Object Oriented Programming

Programming II (CS300)

Assoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Object Oriented Programming

ECE 122. Engineering Problem Solving with Java

VALLIAMMAI ENGINEERING COLLEGE

Object-Oriented Programming (OOP) Fundamental Principles of OOP

Understanding Inheritance and Interfaces

Program Correctness and Efficiency. Chapter 2

Microsoft Visual Basic 2005: Reloaded

BBM 102 Introduction to Programming II Spring Inheritance

10/17/2011. Object Oriented Software Development. Types of interface. Interfaces example

(12-1) OOP: Polymorphism in C++ D & D Chapter 12. Instructor - Andrew S. O Fallon CptS 122 (April 3, 2019) Washington State University

Chapter 14 Abstract Classes and Interfaces

Java Inheritance. Written by John Bell for CS 342, Spring Based on chapter 6 of Learning Java by Niemeyer & Leuck, and other sources.

Exception Handling in C++

Traditional Error Handling

Inheritance and Polymorphism

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS 221 Review. Mason Vail

CH. 2 OBJECT-ORIENTED PROGRAMMING

Lecture 20. Java Exceptional Event Handling. Dr. Martin O Connor CA166

WEEK 13 EXAMPLES: POLYMORPHISM

Framework Fundamentals

Inheritance. Benefits of Java s Inheritance. 1. Reusability of code 2. Code Sharing 3. Consistency in using an interface. Classes

What can go wrong in a Java program while running?

VIRTUAL FUNCTIONS Chapter 10

Assoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

IS 0020 Program Design and Software Tools

UNIT 3 ARRAYS, RECURSION, AND COMPLEXITY CHAPTER 11 CLASSES CONTINUED

OVERRIDING. 7/11/2015 Budditha Hettige 82

Big software. code reuse: The practice of writing program code once and using it in many contexts.

CPSC 427: Object-Oriented Programming

Cpt S 122 Data Structures. Course Review Midterm Exam # 2

CPSC 427: Object-Oriented Programming

Java. Classes 3/3/2014. Summary: Chapters 1 to 10. Java (2)

I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination. June, 2015 BCS-031 : PROGRAMMING IN C ++

Le L c e t c ur u e e 5 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Exception Handling

CS313D: ADVANCED PROGRAMMING LANGUAGE

CGS 2405 Advanced Programming with C++ Course Justification

Introduction to Programming Using Java (98-388)

Object-Oriented Programming

Microsoft Visual C# Step by Step. John Sharp

#using <System.dll> #using <System.Windows.Forms.dll> using namespace System; using namespace System::Windows::Forms;

CS313D: ADVANCED PROGRAMMING LANGUAGE

Polymorphism 2/12/2018. Which statement is correct about overriding private methods in the super class?

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity.

Inheritance. SOTE notebook. November 06, n Unidirectional association. Inheritance ("extends") Use relationship

Inheritance -- Introduction

EXAM Microsoft MTA Software Development Fundamentals. Buy Full Product.

Microsoft. Microsoft Visual C# Step by Step. John Sharp

final Methods and Classes

Exception Handling Pearson Education, Inc. All rights reserved.

Object-Oriented Programming

CS 11 java track: lecture 3

CS 209 Sec. 52 Spring, 2006 Lab 6 - B: Inheritance Instructor: J.G. Neal

The software crisis. code reuse: The practice of writing program code once and using it in many contexts.

Object Oriented Design. Object-Oriented Design. Inheritance & Polymorphism. Class Hierarchy. Goals Robustness Adaptability Flexible code reuse

02 Features of C#, Part 1. Jerry Nixon Microsoft Developer Evangelist Daren May President & Co-founder, Crank211

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming

PROGRAMMING LANGUAGE 2

Absolute C++ Walter Savitch

OOPs Concepts. 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8.

School of Informatics, University of Edinburgh

Saikat Banerjee Page 1

Object Oriented Programming with C++ (24)

Object-Oriented Programming: Polymorphism

Index. Index. More information. block statements 66 y 107 Boolean 107 break 55, 68 built-in types 107

Lecture 4: Extending Classes. Concept

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance

Object-Oriented Design. March 2005 Object Oriented Design 1

CPSC 427: Object-Oriented Programming

Chapter 7. Inheritance

Pieter van den Hombergh Thijs Dorssers Stefan Sobek. January 11, 2018

Java Object Oriented Design. CSC207 Fall 2014

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Java Fundamentals (II)

Transcription:

CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 6 : Abstraction

Lecture Contents 2 Abstract classes Abstract methods Case study: Polymorphic processing Sealed methods & classes Exception handling Interfaces

3 Abstraction Chapter 12 : 12.4, 12.5, 12.6

Abstract Classes and Methods 4 Abstract classes, or abstract base classes cannot be used to instantiate objects. too general, specify only what is common among derived classes. contains one or more abstract methods keyword abstract in their declaration do not provide implementations. Constructors and static methods cannot be declared abstract. Classes that can be used to instantiate objects are called concrete classes. provide implementations to the abstract methods.

Abstract Properties 5 public abstract PropertyType MyProperty { get; set; } // end abstract property An abstract property omits implementations for the get accessor and/or the set accessor. Concrete derived classes must provide implementations for every accessor declared in the abstract property.

6 Tips!!

Case Study: Payroll System 7 A company pays its employees on a weekly basis. The employees are of four types: Salaried employees are paid a fixed weekly salary regardless of the number of hours worked, hourly employees are paid by the hour and receive "time-and-a-half" overtime pay for all hours worked in excess of 40 hours, commission employees are paid a percentage of their sales, and salaried-commission employees receive a base salary plus a percentage of their sales. For the current pay period, the company has decided to reward salaried-commission employees by adding 10% to their base salaries. The company wants to implement an app that performs its payroll calculations polymorphically.

Design 8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

sealed Methods and Classes 24 A method declared sealed in a base class cannot be overridden in a derived class. Methods that are declared private are implicitly sealed. Methods that are declared static also are implicitly sealed, because static methods cannot be overridden either. A derived-class method declared both override and sealed can override a base-class method, but cannot be overridden in classes further down the inheritance hierarchy. Calls to sealed methods (and non-virtual methods) are resolved at compile time this is known as static binding.

sealed Methods and Classes 25 A class that is declared sealed cannot be a base class (i.e., a class cannot extend a sealed class). All methods in a sealed class are implicitly sealed. Class string is a sealed class. This class cannot be extended, so apps that use strings can rely on the functionality of string objects as specified in the Framework Class Library.

26 Text Book Chapter 12 : 12.4, 12.5, 12.6

27 Exception Handling

Introduction 28 An exception is an indication of a problem that occurred during a program s execution. Exception handling enables you to create apps that can handle exceptions in many cases allowing a program to continue executing as if no problems were encountered. Exception handling enables you to write clear, robust and more fault-tolerant programs.

Example 29 an exception is thrown (i.e., an exception occurs) when a method detects a problem.

30

Example revisited 31 catch and handle exceptions displaying an error message and allowing the user to enter another set of values. You may also use Int32.TryParse

Example revisited 32

33

34 Exception Handling mechanism At least one catch block must immediately follow a try block. The statements in the finally clause are guaranteed to execute regardless of whether an exception occurs.

try-catch 35 The point at which an exception occurs is called the throw point. If an exception occurs in a try block, program control immediately transfers to the first catch block matching the type of the thrown exception. After the exception is handled, program control resumes after the last catch block. An uncaught exception (or unhandled exception) is an exception for which there is no matching catch block.

36 method call and exception handling process When an exception is thrown, CLR begins searching an exception handler in the call-stack starting from the method that has thrown the exception. This is repeated for each of the methods down the call-stack until a handler is found which catches the exception. If Main( ) is reached dr. Amal and Khalifa, no Spr handler 17 is found, CLR catches the exception and usually displays an error message

.NET Exception Hierarchy 37 In C#, only objects of class Exception and its derived classes may be thrown and caught. If a program attempts to access an out-of-range array index CLR throws IndexOutOfRangeException. Attempting to use a null reference causes a NullReferenceException. A catch block that specifies a parameter of type Exception can catch all exceptions. makes sense only if the handling behavior is the same for a base class and all derived classes.

38 Be careful!!

39 Text Book Chapter 13 : 13.1 13.3

40 Interfaces

Interfaces 41 An interface declaration begins with the keyword interface and can contain only abstract methods and abstract properties All interface members are implicitly declared both public and abstract. An interface can extend one or more other interfaces to create a more elaborate interface that other classes can implement. specify that it implements the interface must declare each member of the interface with the signature specified in the interface declaration. If any interface member is not implemented declare as abstract

Case study 42

43

44

45

46

47

48

49 Text Book Chapter 12 : 12.4, 12.5, 12.6, 12.7

50 Case Study

51