Object Concepts in C# Class, object, attribute, method, message, instance, encapsulation, polymorphism, inheritance, association, persistence, Generalization/specialization,

Slides:



Advertisements
Similar presentations
METHOD OVERRIDING 1.Sub class can override the methods defined by the super class. 2.Overridden Methods in the sub classes should have same name, same.
Advertisements

1 l Inheritance Basics l Programming with Inheritance l Dynamic Binding and Polymorphism Inheritance.
Object-Oriented Application Development Using VB.NET 1 Chapter 8 Understanding Inheritance and Interfaces.
Inheritance Polymorphism Briana B. Morrison CSE 1302C Spring 2010.
Object Oriented Programming Inheritance and Polymorphism Dr. Mike Spann
Chapter 9 – Inheritance Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved.
 In inheritance the child (subclass) chooses its parent (superclass)  Remember - only public or “protected” methods and variables are inherited  Should.
Inheritance. In this chapter, we will cover: The concept of inheritance Extending classes Overriding superclass methods Working with superclasses that.
Inheritance and Polymorphism Recitation 04/10/2009 CS 180 Department of Computer Science, Purdue University.
Inheritance and Polymorphism Recitation – 10/(16,17)/2008 CS 180 Department of Computer Science, Purdue University.
Object Oriented Concepts in Java Objects Inheritance Encapsulation Polymorphism.
© 2006 Pearson Addison-Wesley. All rights reserved9 A-1 Chapter 9 Advanced Java Topics CS102 Sections 51 and 52 Marc Smith and Jim Ten Eyck Spring 2007.
Chapter 7 - Generalization/Specialization and Inheritance1 Chapter 7 Generalization/Specialization and Inheritance.
LECTURE 07 Programming using C# Inheritance
Inheritance using Java
Programming Languages and Paradigms Object-Oriented Programming.
 Simple payroll application that polymorphically calculates the weekly pay of several different types of employees using each employee’s Earnings method.
Chapter 15 – Inheritance, Virtual Functions, and Polymorphism
“is a”  Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
BPJ444: Business Programming Using Java Classes and Objects Tim McKenna
A class in Java is a software construct that includes fields (also called data fields or class scope variables) to provide data specification, and methods.
Inheritance. Introduction Inheritance is one of the cornerstones of object-oriented programming because it allows the creation of hierarchical classifications.
Often categorize concepts into hierarchies: Inheritance Hierarchies Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved.
Inheritance in the Java programming language J. W. Rider.
Inheritance - Polymorphism ITI 1121 Nour El Kadri.
28-Dec-04polymorhism.ppt1 Polymorphism. 28-Dec-04polymorhism.ppt2 signatures in any programming language, a signature is what distinguishes one function.
Structured Programming Good for programming in the small Often doesn't scale up Limitations –Changes at top may affect lower-level algorithms –Code reuse.
Chapter 10 Inheritance and Polymorphism
Topic 4 Inheritance.
C/C++ 3 Yeting Ge. Static variables Static variables is stored in the static storage. Static variable will be initialized once. 29.cpp 21.cpp.
Lecture 10 Concepts of Programming Languages Arne Kutzner Hanyang University / Seoul Korea.
© 2007 Lawrenceville Press Slide 1 Chapter 8 Objects  A variable of a data type that is a class. Also called an instance of a class.  Stores data  Can.
Programming With Java ICS201 University Of Ha’il1 Chapter 7 Inheritance.
Chapter 10: Introduction to Inheritance. Objectives Learn about the concept of inheritance Extend classes Override superclass methods Call constructors.
10 Polymorphism. 2 Contents Defining Polymorphism Method Overloading Method Overriding Early Binding and Late Binding Implementing Polymorphism.
ISBN Object-Oriented Programming Chapter Chapter
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
COME 339 WEEK 1. Example: The Course Class 2 TestCourceRunCourse.
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
5.1 Basics of defining and using classes A review of class and object definitions A class is a template or blueprint for an object A class defines.
COP INTERMEDIATE JAVA Inheritance, Polymorphism, Interfaces.
COMPUTER SCIENCE & TECHNOLOGY DEGREE PROGRAMME FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UVA WELLASSA ‏ Properties of Object Oriented Programming.
Java Programming Fifth Edition Chapter 9 Introduction to Inheritance.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Modern Programming Tools And Techniques-I
Chapter 12 OOP: Polymorphism, Interfaces and Operator Overloading
Classes and Inheritance
Inheritance and Polymorphism
Computing with C# and the .NET Framework
Programming Language Concepts (CIS 635)
ATS Application Programming: Java Programming
3 Fundamentals of Object-Oriented Programming
OOP’S Concepts in C#.Net
CSC 205 Java Programming II
OBJECT ORIENTED PROGRAMMING II LECTURE 8 GEORGE KOUTSOGIANNAKIS
Advanced Java Topics Chapter 9
Polymorphism CT1513.
Object Oriented Programming
Object-Oriented Programming
Polymorphism Polymorphism - Greek for “many forms”
Java Programming, Second Edition
Object-Oriented Programming
Inheritance.
Chapter 9 Carrano Chapter 10 Small Java
CIS 199 Final Review.
Chapter 11 Inheritance and Polymorphism Part 1
Lecture 10 Concepts of Programming Languages
Chapter 11 Inheritance and Encapsulation and Polymorphism
Computer Science II for Majors
Presentation transcript:

Object Concepts in C# Class, object, attribute, method, message, instance, encapsulation, polymorphism, inheritance, association, persistence, Generalization/specialization, subclass, superclass

Data Encapsulation Example

class EdClass { [STAThread] static void Main(string[] args) { EncapsulatedData ed = new EncapsulatedData(); Console.WriteLine(ed.X()); } Class Method Object Instantiation Message to method X of the EncapsulatedData Object referenced by ed Object Reference Method Attribute For Compiler Storage Class Return Type

Data Encapsulation Example public class EncapsulatedData { private int x; public EncapsulatedData() { x = 25; } public int X() { return x; } public int X(int type) { return x; } Encapsulated Data (private to class) Class Constructor Overloaded method X Scope Modifier

Data Encapsulation Example Execution Yields:

Inheritance and Polymorphism

class InheritanceApplication { [STAThread] static void main(string[] args) { Account acc = new Account(); // create a new Account acc.setBalance(1000); Console.Write("Account interest = "); Console.WriteLine(acc.calcInterest()); acc = new MoneyMarket(); // create a new MoneyMarket object acc.setBalance(1000); Console.Write("MoneyMarket interest = "); Console.WriteLine(acc.calcInterest()); acc = new Savings(); // create a new Savings object acc.setBalance(1000); Console.Write("Savings interest = "); Console.WriteLine(acc.calcInterest()); } Create an object of type Account, MoneyMarket & Savings then calc and display interest Late Binding Polymorphic Behavior

Inheritance and Polymorphism /// /// Account is a superclass used as a base for all types of accounts. /// public class Account { protected double interestRate; protected double balance; public Account() // public constructor { balance = 0.0; interestRate = 0.05; } public virtual double calcInterest() // used to calculate interest { if (balance != 0.0) return balance * (1.0 + interestRate); else return 0.0; } public void setBalance(double bal) // used to set the { balance = bal; } Attributes Superclass Virtual Method that will be overriden Superclass Annual Compounding

Inheritance and Polymorphism public class MoneyMarket : Account // MoneyMarket is derived from the base class { public MoneyMarket() // default constructor which on the base class : base() { } public override double calcInterest() // interest semiannually compounding { if (balance != 0.0) return balance * Math.Pow((1.0 + interestRate/2.0), 2); else return 0.0; } Subclass Inherited From Account Overridden Base Class Method MoneyMarket is a Specialization of Account Note Semi-annual compounding

Inheritance and Polymorphism public class Savings : Account // Savings class inherits from Account { public Savings() // default constructor which call the Account { : base() } public override double calcInterest() // monthly compounding { if (balance != 0.0) return balance * Math.Pow((1.0 + interestRate/12.0), 12); else return 0.0; } Note monthly compounding

Inheritance and Polymorphism An Account object reference was used for each, but the correct interest method was called for each. This is Polymorphism.