C#.Net Software Development Version 1.0. Overview Inheritance Member Access Constructors Polymorphism (Name Hiding) Multilevel Hierarchy Virtual and VTable.

Slides:



Advertisements
Similar presentations
Object Oriented Programming with Java
Advertisements

OOP Abstraction Classes Class Members: Properties & Methods Instance (object) Encapsulation Interfaces Inheritance Composition Polymorphism Using Inheritance.
Web Application Development Slides Credit Umair Javed LUMS.
ITF11006.NET Inheritance. Classes and Inheritance Constructors and Inheritance Modifiers Interfaces Operators.
Java Inheritance. What is inherited A subclass inherits variables and methods from its superclass and all of its ancestors. The subclass can use these.
Inheritance Polymorphism Briana B. Morrison CSE 1302C Spring 2010.
ITEC200 – Week03 Inheritance and Class Hierarchies.
1 Lecture 3 Inheritance. 2 A class that is inherited is called superclass The class that inherits is called subclass A subclass is a specialized version.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
June 1, 2000 Object Oriented Programming in Java (95-707) Java Language Basics 1 Lecture 3 Object Oriented Programming in Java Language Basics Classes,
1 Chapter 6 Inheritance, Interfaces, and Abstract Classes.
Lecture 9 Concepts of Programming Languages
Chapter 10 Classes Continued
Abstract Data Types and Encapsulation Concepts
8.1 Classes & Inheritance Inheritance Objects are created to model ‘things’ Sometimes, ‘things’ may be different, but still have many attributes.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Shallow Versus Deep Copy and Pointers Shallow copy: when two or more pointers of the same types point to the same memory – They point to the same data.
Computer Science and Software Engineering University of Wisconsin - Platteville 7. Inheritance and Polymorphism Yan Shi CS/SE 2630 Lecture Notes.
Inheritance. Types of Inheritance Implementation inheritance means that a type derives from a base type, taking all the base type’s member fields and.
“is a”  Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class.
Lecture 8 Inheritance Richard Gesick. 2 OBJECTIVES How inheritance promotes software reusability. The concepts of base classes and derived classes. To.
Object Oriented Concepts
Object Oriented Concepts Classes II. Object Oriented concepts Encapsulation Composition Inheritance Polymorphism.
CSM-Java Programming-I Spring,2005 Objects and Classes Overview Lesson - 1.
C#C# Classes & Methods CS3260 Dennis A. Fairclough Version 1.1 Classes & Methods CS3260 Dennis A. Fairclough Version 1.1.
Algorithm Programming Bar-Ilan University תשס"ח by Moshe Fresko.
Programming Languages and Paradigms Object-Oriented Programming.
CIS 3301 C# Lesson 7 Introduction to Classes. CIS 3302 Objectives Implement Constructors. Know the difference between instance and static members. Understand.
1 Inheritance. 2 Why use inheritance?  The most important aspect of inheritance is that it expresses a relationship between the new class and the base.
Data Structures Using C++ 2E1 Inheritance An “is-a” relationship –Example: “every employee is a person” Allows new class creation from existing classes.
Chapter 3 Inheritance and Polymorphism Goals: 1.Superclasses and subclasses 2.Inheritance Hierarchy 3.Polymorphism 4.Type Compatibility 5.Abstract Classes.
Copyright 2006 Oxford Consulting, Ltd1 February Polymorphism Polymorphism Polymorphism is a major strength of an object centered paradigm Same.
Object Oriented Software Development
Visual C# 2012 for Programmers © by Pearson Education, Inc. All Rights Reserved.
Module 10: Inheritance in C#. Overview Deriving Classes Implementing Methods Using Sealed Classes Using Interfaces Using Abstract Classes.
C# Classes and Inheritance CNS 3260 C#.NET Software Development.
C# Interfaces C# Class Version 1.0. Copyright © 2012 by Dennis A. Fairclough all rights reserved. 2 Interface  “A surface forming a common boundary between.
CS212: Object Oriented Analysis and Design Lecture 17: Virtual Functions.
Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Object-Oriented Programming Chapter Chapter
OOPs Object oriented programming. Abstract data types  Representationof type and operations in a single unit  Available for other units to create variables.
1 The finalize, clone, and getClass Methods  The finalize method is invoked by the garbage collector on an object when the object becomes garbage.  The.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
ISBN Object-Oriented Programming Chapter Chapter
CS212: Object Oriented Analysis and Design Lecture 16: Runtime Polymorphism.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
1 C# - Inheritance and Polymorphism. 2 1.Inheritance 2.Implementing Inheritance in C# 3.Constructor calls in Inheritance 4.Protected Access Modifier 5.The.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
Object-Oriented Programming Review 1. Object-Oriented Programming Object-Oriented Programming languages vary but generally all support the following features:
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Chapter 2 Objects and Classes
Modern Programming Tools And Techniques-I
Classes and Inheritance
Object-Oriented Programming (OOP) Lecture No. 45
Inheritance and Polymorphism
Object-Oriented Programming
CS212: Object Oriented Analysis and Design
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Extending Classes.
Java Programming Language
Java – Inheritance.
Java Inheritance.
CIS 199 Final Review.
Presentation transcript:

C#.Net Software Development Version 1.0

Overview Inheritance Member Access Constructors Polymorphism (Name Hiding) Multilevel Hierarchy Virtual and VTable Abstract, Sealed and Static Up Casting & Down Casting System.Object most base class 2Copyright © 2008 by Dennis A. Fairclough all rights reserved.

Inheritance Class Single Inheritance Hierarchy Interface Multiple Inheritance Hierarchy (later) Most (ultimate) base class is always object (System.Object) class X : object (X inherits object) { … } class Y : X (Y inherits X) { … } class Z : Y (Z inherits Y) { … } 3Copyright © 2008 by Dennis A. Fairclough all rights reserved.

Inheritance (2) C# Standard When a type inherits from a base class, all members of the base class, except instance constructors, destructors and static constructors, become members of the derived type. The declared accessibility of a base class member does not control whether the member is inherited— inheritance extends to any member that isn’t an instance constructor, static constructor, or destructor. However, an inherited member may not be accessible in a derived type, either because of its declared accessibility (§3.5.1) or because it is hidden by a declaration in the type itself (§ ). 4Copyright © 2008 by Dennis A. Fairclough all rights reserved.

Member Access private object access protected internal program & inherited protected inherited internal program public anyone 5Copyright © 2008 by Dennis A. Fairclough all rights reserved.

Access Modifiers AccessibilityMeaning public Access not limited protected Access limited to this class or classes derived from this class internal Access limited to this program protected internal Access limited to this program or classes derived from this class private Access limited to this class 6Copyright © 2008 by Dennis A. Fairclough all rights reserved.

Constructors Default Parameterized Overloaded Calling base class constructor (: base(…)) Sequence of constructor calls Bottom-Up Call Top-Down Completion 7Copyright © 2008 by Dennis A. Fairclough all rights reserved.

Destructors & Finalize Same name as the containing class ~Data(){ … } No overloading or overiding allowed Calling order Bottom-Up Call Top-Down Completion Finalize() 8Copyright © 2008 by Dennis A. Fairclough all rights reserved.

Polymorphism Hiding Inherited Member Variables Inherited Member Methods Virtual overriding Inherited Member Methods 9Copyright © 2008 by Dennis A. Fairclough all rights reserved.

Multilevel Hierarchy “n” deep hierarchy Most (ultimate) base class (System.Object) Base class Most derived class object Dn D1 D Copyright © 2008 by Dennis A. Fairclough all rights reserved.

Virtual & VTable Virtual Methods Vtable override new 11Copyright © 2008 by Dennis A. Fairclough all rights reserved.

Abstract, Sealed & Static abstract – Must be inherited from sealed – Cannot be inherited from static class – No “this” pointer cannot be inherited from partial – Split a class across files or code segments 12Copyright © 2008 by Dennis A. Fairclough all rights reserved.

Casting Upcasting (Widening Cast) long x = 200; int y = 100; x = y; implicit with no potential loss of precision Downcasting (Narrowing Cast) y = x; //compiler error with potential loss of precision y = (int)x; //explicit cast to over rule the compiler 13Copyright © 2008 by Dennis A. Fairclough all rights reserved.

System.Object (object) class NameDescription ObjectInitializes a new instance of the Object class. NameDescription EqualsOverloaded. Determines whether two Object instances are equal. GetHashCodeServes as a hash function for a particular type. GetHashCode is suitable for use in hashing algorithms and data structures like a hash table. Get TypeGets the Type of the current instance. ReferenceEqualsDetermines whether the specified Object instances are the same instance. ToStringReturns a String that represents the current Object. NameDescription FinalizeAllows an Object to attempt to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. MemberwiseCloneCreates a shallow copy of the current Object. 14Copyright © 2008 by Dennis A. Fairclough all rights reserved.

What did you learn? Single inheritance hierarchy’ Polymorphism – inheritance/virtual (VTABLE) override/new shadow variable/method base Access Modifiers – visability All inheritance “public” 15Copyright © 2008 by Dennis A. Fairclough all rights reserved.