Object Oriented Programming

Size: px
Start display at page:

Download "Object Oriented Programming"

Transcription

1

2 Object Oriented Programming Objects self-contained working units encapsulate data and operations exist independantly of each other (functionally, they may depend) cooperate and communicate to perform a common task Classes are Object Types (abstract data types) are instantiated as Objects Inherit from other Classes form Type Hierarchies may redefine inherited behavior Polymorphically (c)schmiedecke 13 C#-3-OO 2

3 Structs do not inherit are not part of a type hierarchie do not offer polymorphism Why then structs? pragmatic reasons lightweight, less overhead, "cheaper" C# contains numerous "pragmatic" constructs (c)schmiedecke 13 C#-3-OO 3

4 class TypeHierarchy IEnumerable IEnumerable<T> ICollection ICollectio<T> IDictionary IList HashTable ArrayList LinkedList ILst<T> IDictionary<T> ArrayList<T> List<T> Dictionary<T> (c)schmiedecke 13 C#-3-OO 4

5 general and generic types are not directly compatible ArrayList a = new ArrayList<string>() will not compile! ArrayList list = new ArrayList<string>; // Compiler error! use superclasses as variable types to allow for compatibility! Find suitable types for the following situations: a variable to hold all sorts of generic Lists a parameter for passing Hashtables and general Lists a variable to hold both general and generic LinkedLists.. what else can these variables refer to? (c)schmiedecke 13 C#-3-OO 5

6 Interfaces serve as common types for varying implementations a programming "contract" Examples: allow a prototype implementation to be replaced by a production implementation without effect on code tell another programming team what I expect from them specify the contents of a library or have a common variable type for a variety of values. IRegister<T> mylist = new RegisterPrototype<T>(); // simply replace by SecureRegister later. (c)schmiedecke 13 C#-3-OO 6

7 Like in Java, Interfaces are fully abstract classes can extend further interfaces public or internal members automatically public abstract abstract methods abstract properties abstract indexers abstract events (later) public interface IGroupList : IEnumerable { } int Count { get; set } // abstract Property IClassList this[int index]; // abstract Indexer int Find(string name); // abstrac Method void remove(int index); void add(person p); (c)schmiedecke 13 C#-3-OO 7

8 Adapter: your travelagency software was using an old routing library you want to move on to a modern open-source version expose the requirements of your software as an interface write an Adapter class to implement the interface with the new library class Adapter class Adapter Trav elagency OldRouting Trav elagency IOldRouting + computeroute() : string[] + computeroute() : string[] RoutingAdadpter NewRouting + getruotings() : Route[] IOldRouting routing = new RoutingAdapter(); routing.computeroute(destinatiolist); (c)schmiedecke 13 C#-3-OO 8

9 Why didtravelagency not use an interface (IOldRouting) from the beginning? less dependant on the OldRoutingClass Dependency complicates change DIP: Program against interfaces to reduce dependency Always design interfaces for your classes! IList<Route> routelist = new LinkedList<Route>(); // very easy to change to ArrayList or another implementation // very easy to use a verbose debugging type instead during // implementation (c)schmiedecke 13 C#-3-OO 9

10 Proxy a client class refers to a "costly" object e.g. an image which needs downloading resources as long as the object is not really used, a mockup will do: Proxy when needed, the mockup will "secretly" get the object and delegate access. class Adapter class Adapter Photov iiewe Image Photov iiewe IImage + displayimage() : void + displayimage() : void ImageProxy + displayimage() : void Image + displaimage() : void class ImageProxy : IImage { void displayimage() { // download image when called Image img = loadimage(); img.displayimage(); } } (c)schmiedecke 13 C#-3-OO 10

11 These "Tricks" are well-known Design Patterns Every software professional must know them Good solutions to frequent problems Well-knowns structures improve code readability Original List by Gamma, Helm, Johnson and Vlissides Called Gang of Four Patterns or GoF Patterns (c)schmiedecke 13 C#-3-OO 11

12 Just like in Java A class can only inherit from ONE superclass but implement any number of Interfaces some Interfaces are empty "marker interfaces" test for type possible: mylist is ISerializable Interface IEnmuerable { Enumerator getenumerator(); } Interface IEnumerable<T> : IEnumerable { Enumerator<T> get Enumerator(); // addtional method } Interface ISerializable {} // empty marker interface class RandomEnumerator : IEnumerable<T>, ISerializable { } (c)schmiedecke 13 C#-3-OO 12

13 Interfaces are fully abstract Abstract classes are partly implemented specific methods open for implementation in subclasses Design Pattern: Template Method public abstract class Logger { string log; public void log(string logentry) { log += logentry } } public void closelog() { Save(); Clear(); } // template meth. abstract void Save(); public class FileLogger : Logger { public override void Save() { SendToFile(".\logfile.lg", log); } } (c)schmiedecke 13 C#-3-OO 13

14 static fields are not specific to instances the type manages them for all instances (family property) Class Windsor Chief: Queen E II Res: Buckingham P Home: Windsor C. static methods cannot access the instance use static fields, call static methods receive data via parameters create instance to call instance methods Charles William Elizabeth II static classes Kate contain only static members (c)schmiedecke 13 C#-3-OO 14

15 Utilities Global Constants General Computations and Conversions int age = Math.Min(myAge, yourage); string datestring = Convert.ToString(DateTime.Now); File.WriteAllText((@".\logfile.txt", logoutput, Encoding.UTF8); (c)schmiedecke 13 C#-3-OO 15

16 none, internal accessible within assembly (=project) OR public accessible from anywhere static contains only static members abstract only for subclassing, no instantiation OR sealed subclassing prohibited OR none find contradicting combinations! (c)schmiedecke 13 C#-3-OO 16

17 public accessible anywhere none, internal accessible within assembly (=project) protected accessible in subclasses private accessible within class (even other instances) static member belongs to class, not instance abstract not for fields virtual method: open for polymorphic overriding override method: polymorphic overriding const field: compiletime constant readonly field: immutable after initialization (c)schmiedecke 13 C#-3-OO 17

18 C# Fields Properties Indexer Events Delegates Methods JAVA Fields Methods (c)schmiedecke 13 C#-3-OO 18

19 variables, instance and static should be private, for internal use only naming convention: camelcase (start with small letter) extra modifiers for constants: public access reasonable const static const (global constant, naming convention capital, e.g. Math.PI) readonly class Person { private char internalstatus; // cryptic on purpose private static int currentwaitingtime; public const int id; } (c)schmiedecke 13 C#-3-OO 19

20 restricted dynamic typing standard in functional programming best known from scripting languages, like python, ruby, in C# mainly used in Lambda Expressions type of variable open until first assignation var MyVariant; // type yet unknown MyVariant = new DateTime(); // typed fixed to DateTime (c)schmiedecke 13 C#-3-OO 20

21 Programming best practice in all oo programs! private fields with get and set accessors shorthand declaration in C# readonly by omitting the setter class Person { private char internalstatus; // cryptic on purpose private static int currentwaitingtime; } private int id; public int Id { get { return id; } set { id = value; } } //automatic property: public int Id { get ; set } //with resticted access public int Id { get ; private set } (c)schmiedecke 13 C#-3-OO 21

22 void methods and functions like in Java naming convention PascalCase methods can take parameters and throw and handle exceptions (without declaring them) and from an puristic oo point of view, that's enough: an instance method reads or modifies "its" instance fields public class BankAccount { private decimal Balance; private decimal DebtLimit; private decimal Transit; public void Add(decimal amount) { } public void Transfer(decimal amount, BankAccount acc) { if (Balance + DebtLimit < amount) throw new BankingException(); Transit=amount; acc.add(amount); Transit=0; } } (c)schmiedecke 13 C#-3-OO 22

23 pragmatic programmers want: output parameters (if the return value is not enough) flexible parameter lists optional parameters named parameters static void SplitName(string Name, out string FirstNames, out string Surname) { string[] names = Name.Split(','); FirstNames = names[1]; Surname = names[0]; Name = ""; // useless } (c)schmiedecke 13 C#-3-OO 23

24 static void Main() { Person Annie = new Person("smith, annie"); Person Bruce = new Person("wild, bruce"); Exchange(Annie, Bruce) Console.WriteLine(Annie.Name, Bruce.Name); } static void Exchange (Person A, Person B) { Person C = A; A = B; B = C; } // no effect! { string c = A.Name; A.Name = B.Name; B.Name = c; } Annie Bruce smith, annie wild, bruce A B C Parameter passing by (reference) value copies to local variables (c)schmiedecke 13 C#-3-OO 24

25 ref turnes a paramter into a reference parameter out makes it an output parameter (no initialization required) ref and out required at declaration and call! static void SplitName(ref string Name, out string FirstNames, out string Surname) { string[] names = Name.Split(','); FirstNames = names[1]; Surname = names[0]; Name = ""; // clears origial entry } /// SplitName(ref Annie.Name, out Annie.Name, out Bruce.Name); (c)schmiedecke 13 C#-3-OO 25

26 list fixed parameters first, then flexibles params type[ ] name stands for a variable length list of "type" parameters static void Add(out int sum, params int[]vals) { sum = 0; foreach (int i in vals) sum += i; } // Add(out balance, 11,22,33,44,55,66,77,88,99); Add(out sum, sum, a,b,c); Add(out x) (c)schmiedecke 13 C#-3-OO 26

27 Standard in programming is position parameters name-value pairs in many other contexts, e.g. HTTP request allows for arbitrary order in calls method declaration unchanged static void PrintAddress (string street, int numer, int zip, string city) { } // PrintAddress("High Street", 24, 1234, "NewGardens"); PrintAddress("High Street", city: "NewGardens", number: 24, zip: 1234); (c)schmiedecke 13 C#-3-OO 27

28 assign default value in parameter declaration can be omitted at call often combination with named parameters more elegant solution: method overloading static void PrintAddress (string street, int number, int zip = 1234, string city = "NewGardens") { } // PrintAddress("High Street", 24) PrintAddress("Low Street", city: "OldGardens", number: 24); (c)schmiedecke 13 C#-3-OO 28

29 (c)schmiedecke 13 C#-3-OO 29

30 (c)schmiedecke 13 C#-3-OO 30

Object Oriented Programming

Object Oriented Programming Object Oriented Programming Objects self-contained working units encapsulate data and operations exist independantly of each other (functionally, they may depend) cooperate and communicate to perform a

More information

classes, inheritance, interfaces, polymorphism simple and structured types, generics type safeness

classes, inheritance, interfaces, polymorphism simple and structured types, generics type safeness C# is an object oriented language very much like Java a little more modern (int is an object) much more features and add-ons (to keep experienced programmers happy) classes, inheritance, interfaces, polymorphism

More information

Computing is about Data Processing (or "number crunching") Object Oriented Programming is about Cooperating Objects

Computing is about Data Processing (or number crunching) Object Oriented Programming is about Cooperating Objects Computing is about Data Processing (or "number crunching") Object Oriented Programming is about Cooperating Objects C# is fully object-oriented: Everything is an Object: Simple Types, User-Defined Types,

More information

C++ Important Questions with Answers

C++ Important Questions with Answers 1. Name the operators that cannot be overloaded. sizeof,.,.*,.->, ::,? 2. What is inheritance? Inheritance is property such that a parent (or super) class passes the characteristics of itself to children

More information

Chapter 5 Object-Oriented Programming

Chapter 5 Object-Oriented Programming Chapter 5 Object-Oriented Programming Develop code that implements tight encapsulation, loose coupling, and high cohesion Develop code that demonstrates the use of polymorphism Develop code that declares

More information

Java Object Oriented Design. CSC207 Fall 2014

Java Object Oriented Design. CSC207 Fall 2014 Java Object Oriented Design CSC207 Fall 2014 Design Problem Design an application where the user can draw different shapes Lines Circles Rectangles Just high level design, don t write any detailed code

More information

Object-Oriented Programming

Object-Oriented Programming Object-Oriented Programming 1. What is object-oriented programming (OOP)? OOP is a technique to develop logical modules, such as classes that contain properties, methods, fields, and events. An object

More information

Introduce C# as Object Oriented programming language. Explain, tokens,

Introduce C# as Object Oriented programming language. Explain, tokens, Module 2 98 Assignment 1 Introduce C# as Object Oriented programming language. Explain, tokens, lexicals and control flow constructs. 99 The C# Family Tree C Platform Independence C++ Object Orientation

More information

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson Introduction History, Characteristics of Java language Java Language Basics Data types, Variables, Operators and Expressions Anatomy of a Java Program

More information

Object-Oriented Design

Object-Oriented Design Object-Oriented Design Lecturer: Raman Ramsin Lecture 20: GoF Design Patterns Creational 1 Software Patterns Software Patterns support reuse of software architecture and design. Patterns capture the static

More information

CMSC 132: Object-Oriented Programming II

CMSC 132: Object-Oriented Programming II CMSC 132: Object-Oriented Programming II Java Support for OOP Department of Computer Science University of Maryland, College Park Object Oriented Programming (OOP) OO Principles Abstraction Encapsulation

More information

Object oriented programming. Encapsulation. Polymorphism. Inheritance OOP

Object oriented programming. Encapsulation. Polymorphism. Inheritance OOP OOP Object oriented programming Polymorphism Encapsulation Inheritance OOP Class concepts Classes can contain: Constants Delegates Events Fields Constructors Destructors Properties Methods Nested classes

More information

Idioms and Design Patterns. Martin Skogevall IDE, Mälardalen University

Idioms and Design Patterns. Martin Skogevall IDE, Mälardalen University Idioms and Design Patterns Martin Skogevall IDE, Mälardalen University 2005-04-07 Acronyms Object Oriented Analysis and Design (OOAD) Object Oriented Programming (OOD Software Design Patterns (SDP) Gang

More information

Advanced Object-Oriented Programming. 11 Features. C# Programming: From Problem Analysis to Program Design. 4th Edition

Advanced Object-Oriented Programming. 11 Features. C# Programming: From Problem Analysis to Program Design. 4th Edition 11 Features Advanced Object-Oriented Programming C# Programming: From Problem Analysis to Program Design C# Programming: From Problem Analysis to Program Design 1 4th Edition Chapter Objectives Learn the

More information

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

02 Features of C#, Part 1. Jerry Nixon Microsoft Developer Evangelist Daren May President & Co-founder, Crank211 02 Features of C#, Part 1 Jerry Nixon Microsoft Developer Evangelist Daren May President & Co-founder, Crank211 Module Overview Constructing Complex Types Object Interfaces and Inheritance Generics Constructing

More information

Hierarchical inheritance: Contains one base class and multiple derived classes of the same base class.

Hierarchical inheritance: Contains one base class and multiple derived classes of the same base class. 1. What is C#? C# (pronounced "C sharp") is a simple, modern, object oriented, and type safe programming language. It will immediately be familiar to C and C++ programmers. C# combines the high productivity

More information

Topic 7: Algebraic Data Types

Topic 7: Algebraic Data Types Topic 7: Algebraic Data Types 1 Recommended Exercises and Readings From Haskell: The craft of functional programming (3 rd Ed.) Exercises: 5.5, 5.7, 5.8, 5.10, 5.11, 5.12, 5.14 14.4, 14.5, 14.6 14.9, 14.11,

More information

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide AP Computer Science Chapter 10 Implementing and Using Classes Study Guide 1. A class that uses a given class X is called a client of X. 2. Private features of a class can be directly accessed only within

More information

Logistics. Final Exam on Friday at 3pm in CHEM 102

Logistics. Final Exam on Friday at 3pm in CHEM 102 Java Review Logistics Final Exam on Friday at 3pm in CHEM 102 What is a class? A class is primarily a description of objects, or instances, of that class A class contains one or more constructors to create

More information

9 A Preview of.net 2.0

9 A Preview of.net 2.0 473 9 A Preview of.net 2.0 Microsoft.NET is an evolving system that is continuously improved and extended. In late 2003 Microsoft announced.net 2.0 (codename Whidbey) as a major new version of.net; a beta

More information

Objective Questions. BCA Part III Paper XIX (Java Programming) page 1 of 5

Objective Questions. BCA Part III Paper XIX (Java Programming) page 1 of 5 Objective Questions BCA Part III page 1 of 5 1. Java is purely object oriented and provides - a. Abstraction, inheritance b. Encapsulation, polymorphism c. Abstraction, polymorphism d. All of the above

More information

STUDENT LESSON A20 Inheritance, Polymorphism, and Abstract Classes

STUDENT LESSON A20 Inheritance, Polymorphism, and Abstract Classes STUDENT LESSON A20 Inheritance, Polymorphism, and Abstract Classes Java Curriculum for AP Computer Science, Student Lesson A20 1 STUDENT LESSON A20 Inheritance, Polymorphism, and Abstract Classes INTRODUCTION:

More information

Chapter 11. Abstract Data Types and Encapsulation Concepts ISBN

Chapter 11. Abstract Data Types and Encapsulation Concepts ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts ISBN 0-321-49362-1 Chapter 11 Topics The Concept of Abstraction Introduction to Data Abstraction Design Issues for Abstract Data Types Language

More information

Inheritance. OOP components. Another Example. Is a Vs Has a. Virtual Destructor rule. Virtual Functions 4/13/2017

Inheritance. OOP components. Another Example. Is a Vs Has a. Virtual Destructor rule. Virtual Functions 4/13/2017 OOP components For : COP 3330. Object oriented Programming (Using C++) http://www.compgeom.com/~piyush/teach/3330 Data Abstraction Information Hiding, ADTs Encapsulation Type Extensibility Operator Overloading

More information

Industrial Programming

Industrial Programming Industrial Programming Lecture 4: C# Objects & Classes Industrial Programming 1 What is an Object Central to the object-oriented programming paradigm is the notion of an object. Objects are the nouns a

More information

What is an Object. Industrial Programming. What is a Class (cont'd) What is a Class. Lecture 4: C# Objects & Classes

What is an Object. Industrial Programming. What is a Class (cont'd) What is a Class. Lecture 4: C# Objects & Classes What is an Object Industrial Programming Lecture 4: C# Objects & Classes Central to the object-oriented programming paradigm is the notion of an object. Objects are the nouns a person called John Objects

More information

Design issues for objectoriented. languages. Objects-only "pure" language vs mixed. Are subclasses subtypes of the superclass?

Design issues for objectoriented. languages. Objects-only pure language vs mixed. Are subclasses subtypes of the superclass? Encapsulation Encapsulation grouping of subprograms and the data they manipulate Information hiding abstract data types type definition is hidden from the user variables of the type can be declared variables

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

What are the characteristics of Object Oriented programming language?

What are the characteristics of Object Oriented programming language? What are the various elements of OOP? Following are the various elements of OOP:- Class:- A class is a collection of data and the various operations that can be performed on that data. Object- This is

More information

Introduction to C# Applications

Introduction to C# Applications 1 2 3 Introduction to C# Applications OBJECTIVES To write simple C# applications To write statements that input and output data to the screen. To declare and use data of various types. To write decision-making

More information

Chapter 5: Procedural abstraction. Function procedures. Function procedures. Proper procedures and function procedures

Chapter 5: Procedural abstraction. Function procedures. Function procedures. Proper procedures and function procedures Chapter 5: Procedural abstraction Proper procedures and function procedures Abstraction in programming enables distinction: What a program unit does How a program unit works This enables separation of

More information

Introduction to Programming Microsoft.NET Applications with Visual Studio 2008 (C#)

Introduction to Programming Microsoft.NET Applications with Visual Studio 2008 (C#) Introduction to Programming Microsoft.NET Applications with Visual Studio 2008 (C#) Course Number: 6367A Course Length: 3 Days Course Overview This three-day course will enable students to start designing

More information

Absolute C++ Walter Savitch

Absolute C++ Walter Savitch Absolute C++ sixth edition Walter Savitch Global edition This page intentionally left blank Absolute C++, Global Edition Cover Title Page Copyright Page Preface Acknowledgments Brief Contents Contents

More information

CMSC 132: Object-Oriented Programming II

CMSC 132: Object-Oriented Programming II CMSC 132: Object-Oriented Programming II Java Support for OOP Department of Computer Science University of Maryland, College Park Object Oriented Programming (OOP) OO Principles Abstraction Encapsulation

More information

Type Hierarchy. Comp-303 : Programming Techniques Lecture 9. Alexandre Denault Computer Science McGill University Winter 2004

Type Hierarchy. Comp-303 : Programming Techniques Lecture 9. Alexandre Denault Computer Science McGill University Winter 2004 Type Hierarchy Comp-303 : Programming Techniques Lecture 9 Alexandre Denault Computer Science McGill University Winter 2004 February 16, 2004 Lecture 9 Comp 303 : Programming Techniques Page 1 Last lecture...

More information

Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach.

Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach. CMSC 131: Chapter 28 Final Review: What you learned this semester The Big Picture Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach. Java

More information

COMP 401 Spring 2013 Midterm 1

COMP 401 Spring 2013 Midterm 1 COMP 401 Spring 2013 Midterm 1 I have not received nor given any unauthorized assistance in completing this exam. Signature: Name: PID: Please be sure to put your PID at the top of each page. This page

More information

Programming in Visual Basic with Microsoft Visual Studio 2010

Programming in Visual Basic with Microsoft Visual Studio 2010 Programming in Visual Basic with Microsoft Visual Studio 2010 Course 10550; 5 Days, Instructor-led Course Description This course teaches you Visual Basic language syntax, program structure, and implementation

More information

CSE Lecture 3: Objects 2 September Nate Nystrom University of Texas at Arlington

CSE Lecture 3: Objects 2 September Nate Nystrom University of Texas at Arlington CSE 3302 Lecture 3: Objects 2 September 2010 Nate Nystrom University of Texas at Arlington Administration Out of town this afternoon thru Monday HW1 due next Thursday 9/9 Types Last time: strongly typed

More information

COP 3330 Final Exam Review

COP 3330 Final Exam Review COP 3330 Final Exam Review I. The Basics (Chapters 2, 5, 6) a. comments b. identifiers, reserved words c. white space d. compilers vs. interpreters e. syntax, semantics f. errors i. syntax ii. run-time

More information

JAVA MOCK TEST JAVA MOCK TEST II

JAVA MOCK TEST JAVA MOCK TEST II http://www.tutorialspoint.com JAVA MOCK TEST Copyright tutorialspoint.com This section presents you various set of Mock Tests related to Java Framework. You can download these sample mock tests at your

More information

Programming Paradigms

Programming Paradigms PP 2016/17 Unit 4 Ruby Advanced 1/42 Programming Paradigms Unit 4 Ruby Advanced J. Gamper Free University of Bozen-Bolzano Faculty of Computer Science IDSE PP 2016/17 Unit 4 Ruby Advanced 2/42 Outline

More information

administrivia today UML start design patterns Tuesday, September 28, 2010

administrivia today UML start design patterns Tuesday, September 28, 2010 administrivia Assignment 2? promise to get past assignment 1 back soon exam on monday review slides are posted your responsibility to review covers through last week today UML start design patterns 1 Unified

More information

Computer Science 2 Lecture 4 Inheritance: Trinidad Fruit Stand 02/15/2014 Revision : 1.7

Computer Science 2 Lecture 4 Inheritance: Trinidad Fruit Stand 02/15/2014 Revision : 1.7 Computer Science 2 Lecture 4 Inheritance: Trinidad Fruit Stand 02/15/2014 Revision : 1.7 1 Problem Ralph owns the Trinidad Fruit Stand that sells its fruit on the street, and he wants to use a computer

More information

Distributed Systems Recitation 1. Tamim Jabban

Distributed Systems Recitation 1. Tamim Jabban 15-440 Distributed Systems Recitation 1 Tamim Jabban Office Hours Office 1004 Tuesday: 9:30-11:59 AM Thursday: 10:30-11:59 AM Appointment: send an e-mail Open door policy Java: Object Oriented Programming

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 05: Inheritance and Interfaces MOUNA KACEM mouna@cs.wisc.edu Fall 2018 Inheritance and Interfaces 2 Introduction Inheritance and Class Hierarchy Polymorphism Abstract Classes

More information

be used for more than one use case (for instance, for use cases Create User and Delete User, one can have one UserController, instead of two separate

be used for more than one use case (for instance, for use cases Create User and Delete User, one can have one UserController, instead of two separate UNIT 4 GRASP GRASP: Designing objects with responsibilities Creator Information expert Low Coupling Controller High Cohesion Designing for visibility - Applying GoF design patterns adapter, singleton,

More information

PROGRAMMING IN VISUAL BASIC WITH MICROSOFT VISUAL STUDIO Course: 10550A; Duration: 5 Days; Instructor-led

PROGRAMMING IN VISUAL BASIC WITH MICROSOFT VISUAL STUDIO Course: 10550A; Duration: 5 Days; Instructor-led CENTER OF KNOWLEDGE, PATH TO SUCCESS Website: PROGRAMMING IN VISUAL BASIC WITH MICROSOFT VISUAL STUDIO 2010 Course: 10550A; Duration: 5 Days; Instructor-led WHAT YOU WILL LEARN This course teaches you

More information

Programming in C# with Microsoft Visual Studio 2010

Programming in C# with Microsoft Visual Studio 2010 Programming in C# with Microsoft Visual Studio 2010 Course 10266; 5 Days, Instructor-led Course Description: The course focuses on C# program structure, language syntax, and implementation details with.net

More information

Wrapping a complex C++ library for Eiffel. FINAL REPORT July 1 st, 2005

Wrapping a complex C++ library for Eiffel. FINAL REPORT July 1 st, 2005 Wrapping a complex C++ library for Eiffel FINAL REPORT July 1 st, 2005 Semester project Student: Supervising Assistant: Supervising Professor: Simon Reinhard simonrei@student.ethz.ch Bernd Schoeller Bertrand

More information

Learning C# 3.0. Jesse Liberty and Brian MacDonald O'REILLY. Beijing Cambridge Farnham Köln Sebastopol Taipei Tokyo

Learning C# 3.0. Jesse Liberty and Brian MacDonald O'REILLY. Beijing Cambridge Farnham Köln Sebastopol Taipei Tokyo Learning C# 3.0 Jesse Liberty and Brian MacDonald O'REILLY Beijing Cambridge Farnham Köln Sebastopol Taipei Tokyo Table of Contents Preface xv 1. C# and.net Programming 1 Installing C# Express 2 C# 3.0

More information

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

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming Overview of OOP Object Oriented Programming is a programming method that combines: a) Data b) Instructions for processing that data into a self-sufficient object that can be used within a program or in

More information

Concepts of Programming Languages

Concepts of Programming Languages Concepts of Programming Languages Lecture 10 - Object-Oriented Programming Patrick Donnelly Montana State University Spring 2014 Patrick Donnelly (Montana State University) Concepts of Programming Languages

More information

Encapsulation. Mason Vail Boise State University Computer Science

Encapsulation. Mason Vail Boise State University Computer Science Encapsulation Mason Vail Boise State University Computer Science Pillars of Object-Oriented Programming Encapsulation Inheritance Polymorphism Abstraction (sometimes) Object Identity Data (variables) make

More information

Abstract Data Types and Encapsulation Concepts

Abstract Data Types and Encapsulation Concepts Abstract Data Types and Encapsulation Concepts The Concept of Abstraction An abstraction is a view or representation of an entity that includes only the most significant attributes The concept of abstraction

More information

Core Java - SCJP. Q2Technologies, Rajajinagar. Course content

Core Java - SCJP. Q2Technologies, Rajajinagar. Course content Core Java - SCJP Course content NOTE: For exam objectives refer to the SCJP 1.6 objectives. 1. Declarations and Access Control Java Refresher Identifiers & JavaBeans Legal Identifiers. Sun's Java Code

More information

CS 231 Data Structures and Algorithms, Fall 2016

CS 231 Data Structures and Algorithms, Fall 2016 CS 231 Data Structures and Algorithms, Fall 2016 Dr. Bruce A. Maxwell Department of Computer Science Colby College Course Description Focuses on the common structures used to store data and the standard

More information

Chapter 11. Abstract Data Types and Encapsulation Concepts

Chapter 11. Abstract Data Types and Encapsulation Concepts Chapter 11 Abstract Data Types and Encapsulation Concepts Chapter 11 Topics The Concept of Abstraction Introduction to Data Abstraction Design Issues for Abstract Data Types Language Examples Parameterized

More information

A Primer on Design Patterns

A Primer on Design Patterns A Primer on Design Patterns First Edition Rahul Batra This book is for sale at http://leanpub.com/aprimerondesignpatterns This version was published on 2016-03-23 This is a Leanpub book. Leanpub empowers

More information

Interview Questions I received in 2017 and 2018

Interview Questions I received in 2017 and 2018 Interview Questions I received in 2017 and 2018 Table of Contents INTERVIEW QUESTIONS I RECEIVED IN 2017 AND 2018... 1 1 OOPS... 3 1. What is the difference between Abstract and Interface in Java8?...

More information

EEE-425 Programming Languages (2013) 1

EEE-425 Programming Languages (2013) 1 2 Learn about class concepts How to create a class from which objects can be instantiated Learn about instance variables and methods How to declare objects How to organize your classes Learn about public

More information

1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8

1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8 Epic Test Review 1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4 Write a line of code that outputs the phase Hello World to the console without creating a new line character. System.out.print(

More information

VIRTUAL FUNCTIONS Chapter 10

VIRTUAL FUNCTIONS Chapter 10 1 VIRTUAL FUNCTIONS Chapter 10 OBJECTIVES Polymorphism in C++ Pointers to derived classes Important point on inheritance Introduction to virtual functions Virtual destructors More about virtual functions

More information

Inheritance and Polymorphism

Inheritance and Polymorphism Object Oriented Programming Designed and Presented by Dr. Ayman Elshenawy Elsefy Dept. of Systems & Computer Eng.. Al-Azhar University Website: eaymanelshenawy.wordpress.com Email : eaymanelshenawy@azhar.edu.eg

More information

Programming Exercise 14: Inheritance and Polymorphism

Programming Exercise 14: Inheritance and Polymorphism Programming Exercise 14: Inheritance and Polymorphism Purpose: Gain experience in extending a base class and overriding some of its methods. Background readings from textbook: Liang, Sections 11.1-11.5.

More information

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Weiss Chapter 1 terminology (parenthesized numbers are page numbers) Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement

More information

Principles of Object Oriented Programming. Lecture 4

Principles of Object Oriented Programming. Lecture 4 Principles of Object Oriented Programming Lecture 4 Object-Oriented Programming There are several concepts underlying OOP: Abstract Types (Classes) Encapsulation (or Information Hiding) Polymorphism Inheritance

More information

CS112 Lecture: Defining Classes. 1. To describe the process of defining an instantiable class

CS112 Lecture: Defining Classes. 1. To describe the process of defining an instantiable class CS112 Lecture: Defining Classes Last revised 2/3/06 Objectives: 1. To describe the process of defining an instantiable class Materials: 1. BlueJ SavingsAccount example project 2. Handout of code for SavingsAccount

More information

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

Inheritance. Benefits of Java s Inheritance. 1. Reusability of code 2. Code Sharing 3. Consistency in using an interface. Classes Inheritance Inheritance is the mechanism of deriving new class from old one, old class is knows as superclass and new class is known as subclass. The subclass inherits all of its instances variables and

More information

DOWNLOAD PDF CORE JAVA APTITUDE QUESTIONS AND ANSWERS

DOWNLOAD PDF CORE JAVA APTITUDE QUESTIONS AND ANSWERS Chapter 1 : Chapter-wise Java Multiple Choice Questions and Answers Interview MCQs Java Programming questions and answers with explanation for interview, competitive examination and entrance test. Fully

More information

Introduction to Python

Introduction to Python Introduction to Python Version 1.1.5 (12/29/2008) [CG] Page 1 of 243 Introduction...6 About Python...7 The Python Interpreter...9 Exercises...11 Python Compilation...12 Python Scripts in Linux/Unix & Windows...14

More information

QUESTIONS FOR AVERAGE BLOOMERS

QUESTIONS FOR AVERAGE BLOOMERS MANTHLY TEST JULY 2017 QUESTIONS FOR AVERAGE BLOOMERS 1. How many types of polymorphism? Ans- 1.Static Polymorphism (compile time polymorphism/ Method overloading) 2.Dynamic Polymorphism (run time polymorphism/

More information

Agenda. Objects and classes Encapsulation and information hiding Documentation Packages

Agenda. Objects and classes Encapsulation and information hiding Documentation Packages Preliminaries II 1 Agenda Objects and classes Encapsulation and information hiding Documentation Packages Inheritance Polymorphism Implementation of inheritance in Java Abstract classes Interfaces Generics

More information

Object-Oriented Programming in C# (VS 2015)

Object-Oriented Programming in C# (VS 2015) Object-Oriented Programming in C# (VS 2015) This thorough and comprehensive 5-day course is a practical introduction to programming in C#, utilizing the services provided by.net. This course emphasizes

More information

Object Oriented Programming. Solved MCQs - Part 2

Object Oriented Programming. Solved MCQs - Part 2 Object Oriented Programming Solved MCQs - Part 2 Object Oriented Programming Solved MCQs - Part 2 It is possible to declare as a friend A member function A global function A class All of the above What

More information

Applied object oriented programming. 4 th lecture

Applied object oriented programming. 4 th lecture Applied object oriented programming 4 th lecture Today Constructors in depth Class inheritance Interfaces Standard.NET interfaces IComparable IComparer IEquatable IEnumerable ICloneable (and cloning) Kahoot

More information

Object Oriented Design

Object Oriented Design Object Oriented Design Lecture 3: Introduction to C++ (Continue) Examples using declarations that eliminate the need to repeat the std:: prefix 1 Examples using namespace std; enables a program to use

More information

4.1 Introduction Programming preliminaries Constructors Destructors An example... 3

4.1 Introduction Programming preliminaries Constructors Destructors An example... 3 Department of Computer Science Tackling Design Patterns Chapter 4: Factory Method design pattern Copyright c 2016 by Linda Marshall and Vreda Pieterse. All rights reserved. Contents 4.1 Introduction.................................

More information

An Introduction to C++

An Introduction to C++ An Introduction to C++ Introduction to C++ C++ classes C++ class details To create a complex type in C In the.h file Define structs to store data Declare function prototypes The.h file serves as the interface

More information

How to be a C# ninja in 10 easy steps. Benjamin Day

How to be a C# ninja in 10 easy steps. Benjamin Day How to be a C# ninja in 10 easy steps Benjamin Day Benjamin Day Consultant, Coach, Trainer Scrum.org Classes Professional Scrum Developer (PSD) Professional Scrum Foundations (PSF) TechEd, VSLive, DevTeach,

More information

Object-Oriented Concepts and Principles (Adapted from Dr. Osman Balci)

Object-Oriented Concepts and Principles (Adapted from Dr. Osman Balci) Object-Oriented Concepts and Principles (Adapted from Dr. Osman Balci) Sung Hee Park Department of Mathematics and Computer Science Virginia State University September 18, 2012 The Object-Oriented Paradigm

More information

Design Patterns. Manuel Mastrofini. Systems Engineering and Web Services. University of Rome Tor Vergata June 2011

Design Patterns. Manuel Mastrofini. Systems Engineering and Web Services. University of Rome Tor Vergata June 2011 Design Patterns Lecture 1 Manuel Mastrofini Systems Engineering and Web Services University of Rome Tor Vergata June 2011 Definition A pattern is a reusable solution to a commonly occurring problem within

More information

Problem Solving with C++

Problem Solving with C++ GLOBAL EDITION Problem Solving with C++ NINTH EDITION Walter Savitch Kendrick Mock Ninth Edition PROBLEM SOLVING with C++ Problem Solving with C++, Global Edition Cover Title Copyright Contents Chapter

More information

Polymorphism. Contents. Assignment to Derived Class Object. Assignment to Base Class Object

Polymorphism. Contents. Assignment to Derived Class Object. Assignment to Base Class Object Polymorphism C++ Object Oriented Programming Pei-yih Ting NTOU CS 26-1 Contents Assignment to base / derived types of objects Assignment to base / derived types of pointers Heterogeneous container and

More information

Chapter 11. Abstract Data Types and Encapsulation Concepts

Chapter 11. Abstract Data Types and Encapsulation Concepts Chapter 11 Abstract Data Types and Encapsulation Concepts Chapter 11 Topics The Concept of Abstraction Introduction to Data Abstraction Design Issues for Abstract Data Types Language Examples Parameterized

More information

G Programming Languages Spring 2010 Lecture 9. Robert Grimm, New York University

G Programming Languages Spring 2010 Lecture 9. Robert Grimm, New York University G22.2110-001 Programming Languages Spring 2010 Lecture 9 Robert Grimm, New York University 1 Review Last week Modules 2 Outline Classes Encapsulation and Inheritance Initialization and Finalization Dynamic

More information

Patterns for polymorphic operations

Patterns for polymorphic operations Patterns for polymorphic operations Three small object structural patterns for dealing with polymorphism Alexander A. Horoshilov hor@epsylontech.com Abstract Polymorphism is one of the main elements of

More information

Distributed Systems Recitation 1. Tamim Jabban

Distributed Systems Recitation 1. Tamim Jabban 15-440 Distributed Systems Recitation 1 Tamim Jabban Office Hours Office 1004 Sunday, Tuesday: 9:30-11:59 AM Appointment: send an e-mail Open door policy Java: Object Oriented Programming A programming

More information

And Even More and More C++ Fundamentals of Computer Science

And Even More and More C++ Fundamentals of Computer Science And Even More and More C++ Fundamentals of Computer Science Outline C++ Classes Special Members Friendship Classes are an expanded version of data structures (structs) Like structs, the hold data members

More information

Object Oriented Paradigm

Object Oriented Paradigm Object Oriented Paradigm History Simula 67 A Simulation Language 1967 (Algol 60 based) Smalltalk OO Language 1972 (1 st version) 1980 (standard) Background Ideas Record + code OBJECT (attributes + methods)

More information

Software Construction

Software Construction Lecture 7: Type Hierarchy, Iteration Abstraction Software Construction in Java for HSE Moscow Tom Verhoeff Eindhoven University of Technology Department of Mathematics & Computer Science Software Engineering

More information

Programming Language Concepts Object-Oriented Programming. Janyl Jumadinova 28 February, 2017

Programming Language Concepts Object-Oriented Programming. Janyl Jumadinova 28 February, 2017 Programming Language Concepts Object-Oriented Programming Janyl Jumadinova 28 February, 2017 Three Properties of Object-Oriented Languages: Encapsulation Inheritance Dynamic method binding (polymorphism)

More information

CS 1302 Chapter 9 (Review) Object & Classes

CS 1302 Chapter 9 (Review) Object & Classes CS 1302 Chapter 9 (Review) Object & Classes Reference Sections 9.2-9.5, 9.7-9.14 9.2 Defining Classes for Objects 1. A class is a blueprint (or template) for creating objects. A class defines the state

More information

EEE-425 Programming Languages (2013) 1

EEE-425 Programming Languages (2013) 1 2 Learn about class concepts How to create a class from which objects can be instantiated Learn about instance variables and methods How to declare objects How to organize your classes Learn about public

More information

Lecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction

Lecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction Lecture 13: Object orientation Object oriented programming Introduction, types of OO languages Key concepts: Encapsulation, Inheritance, Dynamic binding & polymorphism Other design issues Smalltalk OO

More information

Introduction to Object-Oriented Programming

Introduction to Object-Oriented Programming 1/9 Introduction to Object-Oriented Programming Conception et programmation orientées object, B. Meyer, Eyrolles Object-Oriented Software Engineering, T. C. Lethbridge, R. Laganière, McGraw Hill Design

More information

+ Abstract Data Types

+ Abstract Data Types Linked Lists Abstract Data Types An Abstract Data Type (ADT) is: a set of values a set of operations Sounds familiar, right? I gave a similar definition for a data structure. Abstract Data Types Abstract

More information

Object Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia

Object Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia Object Oriented Programming in Java Jaanus Pöial, PhD Tallinn, Estonia Motivation for Object Oriented Programming Decrease complexity (use layers of abstraction, interfaces, modularity,...) Reuse existing

More information

Goals of design. satisfies problem requirements, usable error free, resistant to incorrect input. readable, not purposefully cryptic.

Goals of design. satisfies problem requirements, usable error free, resistant to incorrect input. readable, not purposefully cryptic. OOP design revisited design revisited 1 Goals of design usable software robust implementable understandable reusable generalizable extendable solves the problem, satisfies problem requirements, usable

More information

C#: framework overview and in-the-small features

C#: framework overview and in-the-small features Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer C#: framework overview and in-the-small features Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer

More information