Lecture 02 - DSA

60
Programming Languages are Not the Same Dr.Haitham A. El-Ghareeb Information Systems Department Faculty of Computers and Information Sciences Mansoura University [email protected] September 23, 2012 Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 1 / 29

description

2nd Year, Faculty of Computers and Information Sciences, Mansoura University, Egypt

Transcript of Lecture 02 - DSA

Page 1: Lecture 02 - DSA

Programming Languages are Not the Same

Dr.Haitham A. El-Ghareeb

Information Systems DepartmentFaculty of Computers and Information Sciences

Mansoura University

[email protected]

September 23, 2012

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 1 / 29

Page 2: Lecture 02 - DSA

Programming Languages

used for controlling the behavior of a machine (often a computer).

programming languages conform to rules for syntax and semantics.

There are thousands of programming languages and new ones arecreated every year.

Few languages ever become sufficiently popular that they are used bymore than a few people

professional programmers may use dozens of languages in a career.

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 2 / 29

Page 3: Lecture 02 - DSA

Programming Languages

used for controlling the behavior of a machine (often a computer).

programming languages conform to rules for syntax and semantics.

There are thousands of programming languages and new ones arecreated every year.

Few languages ever become sufficiently popular that they are used bymore than a few people

professional programmers may use dozens of languages in a career.

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 2 / 29

Page 4: Lecture 02 - DSA

Programming Languages

used for controlling the behavior of a machine (often a computer).

programming languages conform to rules for syntax and semantics.

There are thousands of programming languages and new ones arecreated every year.

Few languages ever become sufficiently popular that they are used bymore than a few people

professional programmers may use dozens of languages in a career.

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 2 / 29

Page 5: Lecture 02 - DSA

Programming Languages

used for controlling the behavior of a machine (often a computer).

programming languages conform to rules for syntax and semantics.

There are thousands of programming languages and new ones arecreated every year.

Few languages ever become sufficiently popular that they are used bymore than a few people

professional programmers may use dozens of languages in a career.

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 2 / 29

Page 6: Lecture 02 - DSA

Programming Languages

used for controlling the behavior of a machine (often a computer).

programming languages conform to rules for syntax and semantics.

There are thousands of programming languages and new ones arecreated every year.

Few languages ever become sufficiently popular that they are used bymore than a few people

professional programmers may use dozens of languages in a career.

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 2 / 29

Page 7: Lecture 02 - DSA

Programming Languages

used for controlling the behavior of a machine (often a computer).

programming languages conform to rules for syntax and semantics.

There are thousands of programming languages and new ones arecreated every year.

Few languages ever become sufficiently popular that they are used bymore than a few people

professional programmers may use dozens of languages in a career.

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 2 / 29

Page 8: Lecture 02 - DSA

Basis for Comparing Programming Languages

1 Object Orientation

2 Static vs. Dynamic Typing

3 Generic Classes

4 Inheritence

5 Feature Renaming

6 Method Overloading

7 Operator Overloading

8 Higher Order Functions & Lexical Closures

9 Garbage Collection

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 3 / 29

Page 9: Lecture 02 - DSA

Basis for Comparing Programming Languages (Cont.)

10 Uniform Access

11 Class Variables/Methods

12 Reflection

13 Access Control

14 Design by Contract

15 Multithreading

16 Regular Expressions

17 Pointer Arithmetic

18 Language Integration

19 Built-In Security

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 4 / 29

Page 10: Lecture 02 - DSA

Object Orientation

There are several qualities for Object Oriented Languages:

Encapsulation / Information Hiding

Inheritance

Polymorphism/Dynamic Binding

All pre-defined types are Objects

All operations performed by sending messages to Objects

All user-defined types are Objects

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 5 / 29

Page 11: Lecture 02 - DSA

Object Orientation

There are several qualities for Object Oriented Languages:

Encapsulation / Information Hiding

Inheritance

Polymorphism/Dynamic Binding

All pre-defined types are Objects

All operations performed by sending messages to Objects

All user-defined types are Objects

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 5 / 29

Page 12: Lecture 02 - DSA

Object Orientation

There are several qualities for Object Oriented Languages:

Encapsulation / Information Hiding

Inheritance

Polymorphism/Dynamic Binding

All pre-defined types are Objects

All operations performed by sending messages to Objects

All user-defined types are Objects

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 5 / 29

Page 13: Lecture 02 - DSA

Object Orientation

There are several qualities for Object Oriented Languages:

Encapsulation / Information Hiding

Inheritance

Polymorphism/Dynamic Binding

All pre-defined types are Objects

All operations performed by sending messages to Objects

All user-defined types are Objects

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 5 / 29

Page 14: Lecture 02 - DSA

Object Orientation

There are several qualities for Object Oriented Languages:

Encapsulation / Information Hiding

Inheritance

Polymorphism/Dynamic Binding

All pre-defined types are Objects

All operations performed by sending messages to Objects

All user-defined types are Objects

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 5 / 29

Page 15: Lecture 02 - DSA

Object Orientation

There are several qualities for Object Oriented Languages:

Encapsulation / Information Hiding

Inheritance

Polymorphism/Dynamic Binding

All pre-defined types are Objects

All operations performed by sending messages to Objects

All user-defined types are Objects

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 5 / 29

Page 16: Lecture 02 - DSA

Object Orientation

There are several qualities for Object Oriented Languages:

Encapsulation / Information Hiding

Inheritance

Polymorphism/Dynamic Binding

All pre-defined types are Objects

All operations performed by sending messages to Objects

All user-defined types are Objects

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 5 / 29

Page 17: Lecture 02 - DSA

Static vs. Dynamic Typing

The debate between static and dynamic typing has raged inObject-Oriented circles for many years with no clear conclusion.

Proponents of dynamic typing contend that it is more flexible andallows for increased productivity.

Those who prefer static typing argue that it enforces safer, morereliable code, and increases efficiency of the resulting product.

A dynamic type system doesnt require variables to be declared as aspe- cific type. Any variable can contain any value or object.

Statically-typed languages require that all variables are declared witha specific type.

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 6 / 29

Page 18: Lecture 02 - DSA

Static vs. Dynamic Typing

The debate between static and dynamic typing has raged inObject-Oriented circles for many years with no clear conclusion.

Proponents of dynamic typing contend that it is more flexible andallows for increased productivity.

Those who prefer static typing argue that it enforces safer, morereliable code, and increases efficiency of the resulting product.

A dynamic type system doesnt require variables to be declared as aspe- cific type. Any variable can contain any value or object.

Statically-typed languages require that all variables are declared witha specific type.

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 6 / 29

Page 19: Lecture 02 - DSA

Static vs. Dynamic Typing

The debate between static and dynamic typing has raged inObject-Oriented circles for many years with no clear conclusion.

Proponents of dynamic typing contend that it is more flexible andallows for increased productivity.

Those who prefer static typing argue that it enforces safer, morereliable code, and increases efficiency of the resulting product.

A dynamic type system doesnt require variables to be declared as aspe- cific type. Any variable can contain any value or object.

Statically-typed languages require that all variables are declared witha specific type.

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 6 / 29

Page 20: Lecture 02 - DSA

Static vs. Dynamic Typing

The debate between static and dynamic typing has raged inObject-Oriented circles for many years with no clear conclusion.

Proponents of dynamic typing contend that it is more flexible andallows for increased productivity.

Those who prefer static typing argue that it enforces safer, morereliable code, and increases efficiency of the resulting product.

A dynamic type system doesnt require variables to be declared as aspe- cific type. Any variable can contain any value or object.

Statically-typed languages require that all variables are declared witha specific type.

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 6 / 29

Page 21: Lecture 02 - DSA

Static vs. Dynamic Typing

The debate between static and dynamic typing has raged inObject-Oriented circles for many years with no clear conclusion.

Proponents of dynamic typing contend that it is more flexible andallows for increased productivity.

Those who prefer static typing argue that it enforces safer, morereliable code, and increases efficiency of the resulting product.

A dynamic type system doesnt require variables to be declared as aspe- cific type. Any variable can contain any value or object.

Statically-typed languages require that all variables are declared witha specific type.

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 6 / 29

Page 22: Lecture 02 - DSA

Static vs. Dynamic Typing

The debate between static and dynamic typing has raged inObject-Oriented circles for many years with no clear conclusion.

Proponents of dynamic typing contend that it is more flexible andallows for increased productivity.

Those who prefer static typing argue that it enforces safer, morereliable code, and increases efficiency of the resulting product.

A dynamic type system doesnt require variables to be declared as aspe- cific type. Any variable can contain any value or object.

Statically-typed languages require that all variables are declared witha specific type.

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 6 / 29

Page 23: Lecture 02 - DSA

Generic Classes

refer to the ability to parameterize a class with specific data types.

A common example is a stack class that is parameterized by the typeof elements it contains.

it allows statically typed languages to retain their compile-time typesafety

Dynamically typed languages do not need parameterized types inorder to support generic programming

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 7 / 29

Page 24: Lecture 02 - DSA

Generic Classes

refer to the ability to parameterize a class with specific data types.

A common example is a stack class that is parameterized by the typeof elements it contains.

it allows statically typed languages to retain their compile-time typesafety

Dynamically typed languages do not need parameterized types inorder to support generic programming

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 7 / 29

Page 25: Lecture 02 - DSA

Generic Classes

refer to the ability to parameterize a class with specific data types.

A common example is a stack class that is parameterized by the typeof elements it contains.

it allows statically typed languages to retain their compile-time typesafety

Dynamically typed languages do not need parameterized types inorder to support generic programming

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 7 / 29

Page 26: Lecture 02 - DSA

Generic Classes

refer to the ability to parameterize a class with specific data types.

A common example is a stack class that is parameterized by the typeof elements it contains.

it allows statically typed languages to retain their compile-time typesafety

Dynamically typed languages do not need parameterized types inorder to support generic programming

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 7 / 29

Page 27: Lecture 02 - DSA

Generic Classes

refer to the ability to parameterize a class with specific data types.

A common example is a stack class that is parameterized by the typeof elements it contains.

it allows statically typed languages to retain their compile-time typesafety

Dynamically typed languages do not need parameterized types inorder to support generic programming

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 7 / 29

Page 28: Lecture 02 - DSA

Inheritence

the ability for a class or object to be defined as an extension orspecialization of another class or object.

Most object-oriented languages support class-based inheritance

others such as SELF and JavaScript support object-based inheritance

A few languages, notably Python and Ruby, support both class- andobject-based inheritance, in which a class can inherit from anotherclass and individual objects can be extended at run time

Though there are identified and classified as many as 17 differentforms of inheritance. Even so, most languages provide only a fewsyntactic constructs for inheritance

Multiple Inheritence

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 8 / 29

Page 29: Lecture 02 - DSA

Inheritence

the ability for a class or object to be defined as an extension orspecialization of another class or object.

Most object-oriented languages support class-based inheritance

others such as SELF and JavaScript support object-based inheritance

A few languages, notably Python and Ruby, support both class- andobject-based inheritance, in which a class can inherit from anotherclass and individual objects can be extended at run time

Though there are identified and classified as many as 17 differentforms of inheritance. Even so, most languages provide only a fewsyntactic constructs for inheritance

Multiple Inheritence

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 8 / 29

Page 30: Lecture 02 - DSA

Inheritence

the ability for a class or object to be defined as an extension orspecialization of another class or object.

Most object-oriented languages support class-based inheritance

others such as SELF and JavaScript support object-based inheritance

A few languages, notably Python and Ruby, support both class- andobject-based inheritance, in which a class can inherit from anotherclass and individual objects can be extended at run time

Though there are identified and classified as many as 17 differentforms of inheritance. Even so, most languages provide only a fewsyntactic constructs for inheritance

Multiple Inheritence

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 8 / 29

Page 31: Lecture 02 - DSA

Inheritence

the ability for a class or object to be defined as an extension orspecialization of another class or object.

Most object-oriented languages support class-based inheritance

others such as SELF and JavaScript support object-based inheritance

A few languages, notably Python and Ruby, support both class- andobject-based inheritance, in which a class can inherit from anotherclass and individual objects can be extended at run time

Though there are identified and classified as many as 17 differentforms of inheritance. Even so, most languages provide only a fewsyntactic constructs for inheritance

Multiple Inheritence

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 8 / 29

Page 32: Lecture 02 - DSA

Inheritence

the ability for a class or object to be defined as an extension orspecialization of another class or object.

Most object-oriented languages support class-based inheritance

others such as SELF and JavaScript support object-based inheritance

A few languages, notably Python and Ruby, support both class- andobject-based inheritance, in which a class can inherit from anotherclass and individual objects can be extended at run time

Though there are identified and classified as many as 17 differentforms of inheritance. Even so, most languages provide only a fewsyntactic constructs for inheritance

Multiple Inheritence

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 8 / 29

Page 33: Lecture 02 - DSA

Inheritence

the ability for a class or object to be defined as an extension orspecialization of another class or object.

Most object-oriented languages support class-based inheritance

others such as SELF and JavaScript support object-based inheritance

A few languages, notably Python and Ruby, support both class- andobject-based inheritance, in which a class can inherit from anotherclass and individual objects can be extended at run time

Though there are identified and classified as many as 17 differentforms of inheritance. Even so, most languages provide only a fewsyntactic constructs for inheritance

Multiple Inheritence

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 8 / 29

Page 34: Lecture 02 - DSA

Inheritence

the ability for a class or object to be defined as an extension orspecialization of another class or object.

Most object-oriented languages support class-based inheritance

others such as SELF and JavaScript support object-based inheritance

A few languages, notably Python and Ruby, support both class- andobject-based inheritance, in which a class can inherit from anotherclass and individual objects can be extended at run time

Though there are identified and classified as many as 17 differentforms of inheritance. Even so, most languages provide only a fewsyntactic constructs for inheritance

Multiple Inheritence

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 8 / 29

Page 35: Lecture 02 - DSA

Feature Renaming

Feature renaming is the ability for a class or object to rename one of itsfeatures (a term used to collectively refer to attributes and methods) thatit inherited from a super class.

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 9 / 29

Page 36: Lecture 02 - DSA

Method Overloading

Method overloading (also referred to as parametric polymorphism) isthe ability for a class, module, or other scope to have two or moremethods with the same name.

Calls to these methods are disambiguated by the number and/or typeof arguments passed to the method at the call site.

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 10 / 29

Page 37: Lecture 02 - DSA

Operator Overloading

ability for a programmer to define an operator (such as +, or *) foruser-defined types.

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 11 / 29

Page 38: Lecture 02 - DSA

Higher Order Functions and Lexical Closures

Higher Order Functions:

functions that can be treated as if they were data objects.I they can be bound to variables (including the ability to be stored in

collections)I can be passed to other functions as parametersI can be returned as the result of other functions

Lexical Closure: bundling up the lexical (static) scope surrounding thefunction with the function itself, so that the function carries itssurrounding environment around with it wherever it may be used.

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 12 / 29

Page 39: Lecture 02 - DSA

Garbage Collection

mechanism allowing a language implementation to free memory of unusedobjects on behalf of the programmer

Reference Counting

Mark and Sweep

Generational

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 13 / 29

Page 40: Lecture 02 - DSA

Uniform Access

All services offered by a mod- ule should be available through a uniformnotation, which does not betray whether they are implemented throughstorage or through computation.

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 14 / 29

Page 41: Lecture 02 - DSA

Class Variables/Methods

Class variables and methods are owned by a class, and not any particularinstance of a class. This means that for however many instances of a classexist at any given point in time, only one copy of each classvariable/method exists and is shared by every instance of the class.

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 15 / 29

Page 42: Lecture 02 - DSA

Reflection

ability for a program to determine various pieces of information about anobject at run-time. Most object-oriented languages support some form ofreflection. This includes the ability to determine:

the type of the object,

its inheritance structure,

and the methods it contains, including the number and types ofparameters and return types.

It might also include the ability for determining the names and typesof attributes of the object.

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 16 / 29

Page 43: Lecture 02 - DSA

Access Control

ability for a modules implementation to remain hidden behind its publicinterface.

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 17 / 29

Page 44: Lecture 02 - DSA

Design by Contract

Design by Contract (DBC) is the ability to incorporate important aspectsof a specification into the software that is implementing it. The mostimportant features of DBC are:

Pre-conditions, which are conditions that must be true before amethod is invoked

Post-conditions, which are conditions guaranteed to be true after theinvocation of a method

Invariants, which are conditions guaranteed to be true at any stablepoint during the lifetime of an object

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 18 / 29

Page 45: Lecture 02 - DSA

Multithreading

ability for a single process to process two or more tasks concurrently.

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 19 / 29

Page 46: Lecture 02 - DSA

Regular Expressions

pattern matching constructs capable of recognizing the class of languagesknown as regular languages.

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 20 / 29

Page 47: Lecture 02 - DSA

Pointer Arithmetic

ability for a language to directly manipulate memory addresses and theircontents.

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 21 / 29

Page 48: Lecture 02 - DSA

Language Integration

It is important for a high level language (particularly interpretedlanguages) to be able to integrate seamlessly with other languages.

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 22 / 29

Page 49: Lecture 02 - DSA

Built-In Security

language implementations ability to determine whether or not a piece ofcode comes from a trusted source (such as the users hard disk), limitingthe permissions of the code if it does not.

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 23 / 29

Page 50: Lecture 02 - DSA

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 24 / 29

Page 51: Lecture 02 - DSA

Quick Tour of C#

Brief Overview

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 25 / 29

Page 52: Lecture 02 - DSA

Namespaces

namespace DataStructures . Professor {class Haitham {. . .}}

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 26 / 29

Page 53: Lecture 02 - DSA

Classes

public class Haitham : Professor , IBlogger , IMozillaReMo {public string name ;public Haitham ( string name ) {this . name = name ; // more fields and methods here

}

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 27 / 29

Page 54: Lecture 02 - DSA

Attributes

class ProfessorHaitham {/ / . . .[ SecretOverride ( ” . . . ” ) ] public void Teach ( Subjects ←↩

datastructures2012 ) {/ / . . .}}

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 28 / 29

Page 55: Lecture 02 - DSA

Interfaces

interface IMozillaReMo {IBrowser FavouriteBrowser {get ; s e t ;}void Browse ( ) ;}

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 29 / 29

Page 56: Lecture 02 - DSA

Enums

enum CoursesITeach {DataStructuresAndAlgorithms ,SystemAnalysisAndDesign ,ResearchMethodologies ,DataBase

}

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 30 / 29

Page 57: Lecture 02 - DSA

Struct

struct Faculty {public float name ;public Faculty ( String name ) {/ / . . .}}

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 31 / 29

Page 58: Lecture 02 - DSA

Methods

class Haitham {/ / . . .public void GoToLecture ( string LectureName ) {Point location = this . targetDatabase . Find ( targetName ) ;this . FlyToLocation ( location ) ;}}

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 32 / 29

Page 59: Lecture 02 - DSA

Virtual and Override Methods

class GiantRobot {/ / . . .public virtual void TravelTo ( Point destination ) {this . TurnTowards ( destination ) ;wh i l e ( this . Location != destination ) {this . Trudge ( ) ;}}}

class FlyingRobot : GiantRobot {/ / . . .public override void TravelTo ( Point destination ) {i f ( this . WingState == WingState . Operational ) {this . FlyTo ( destination ) ;// whee !} e l s e {base . TravelTo ( destination ) ; // oh well . . .}}}

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 33 / 29

Page 60: Lecture 02 - DSA

Methods

class Haitham {/ / . . .public void GoToLecture ( string LectureName ) {Point location = this . targetDatabase . Find ( targetName ) ;this . FlyToLocation ( location ) ;}}

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 23, 2012 34 / 29