Section 3: Component/Object Oriented Programming, Events, and Delegates in.NET Jim Fiddelke, Greenbrier & Russel.

Slides:



Advertisements
Similar presentations
Object Oriented Programming
Advertisements

Module 8 “Polymorphism and Inheritance”. Outline Understanding Inheritance Inheritance Diagrams Constructors in Derived Classes Type Compatibility Polymorphism.
IEG 3080 Tutorial 2 Jack Chan. Prepared by Jack Chan, Spring 2007 Outline.Net Platform Object Oriented Concepts Encapsulation Inheritance Polymorphism.
CS 211 Inheritance AAA.
CS 106 Introduction to Computer Science I 04 / 11 / 2008 Instructor: Michael Eckmann.
Chapter 11: Implementing Inheritance and Association Visual Basic.NET Programming: From Problem Analysis to Program Design.
12-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Section 5 – Classes. Object-Oriented Language Features Abstraction –Abstract or identify the objects involved in the problem Encapsulation –Packaging.
Session 07: C# OOP 4 Review of: Inheritance and Polymorphism. Static and dynamic type of an object. Abstract Classes. Interfaces. FEN AK - IT:
More about classes and objects Classes in Visual Basic.NET.
1 Inheritance & Interface. 2 Why Inheritance? Common properties? Methods to send congratulations to Employees and Customers Public Sub SendCongratulationsE(ByVal.
CS 106 Introduction to Computer Science I 04 / 16 / 2010 Instructor: Michael Eckmann.
Advanced Object-Oriented Programming Features
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
Object-oriented Programming Concepts
VB Classes ISYS 573. Object-Oriented Concepts Abstraction: –To create a model of an object, for the purpose of determining the characteristics (properties)
Inheritance. © 2004 Pearson Addison-Wesley. All rights reserved 8-2 Inheritance Inheritance is a fundamental object-oriented design technique used to.
Object-Oriented Programming in Visual Basic.NET. Overview Defining Classes Creating and Destroying Objects Inheritance Interfaces Working with Classes.
2.5 OOP Principles Part 1 academy.zariba.com 1. Lecture Content 1.Fundamental Principles of OOP 2.Inheritance 3.Abstraction 4.Encapsulation 2.
Inheritance. Types of Inheritance Implementation inheritance means that a type derives from a base type, taking all the base type’s member fields and.
Inheritance Chapter 14. What is inheritance?  The ability to create a class from another class, the “parent” class, extending the functionality and state.
Object Oriented Software Development
Module 7: Object-Oriented Programming in Visual Basic .NET
An Object-Oriented Approach to Programming Logic and Design
CSE 332: C++ templates This Week C++ Templates –Another form of polymorphism (interface based) –Let you plug different types into reusable code Assigned.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Programming Pillars Introduction to Object- Oriented Programming.
Object Oriented Programming with C# Session: August-December 2009 Subject: C# Programming.
Tuc Goodwin  Object and Component-Oriented Programming  Classes in C#  Scope and Accessibility  Methods and Properties  Nested.
Encapsulation, Inheritance & Polymorphism. OOP Properties Encapsulation ­The process of creating programs so that information within a class is not accessible.
Polymorphic support in C# Let us now examine third pillar of OOP i.e. Polymorphism.. Recall that the Employee base class defined a method named GiveBonus(),
CIS 3301 C# Lesson 7 Introduction to Classes. CIS 3302 Objectives Implement Constructors. Know the difference between instance and static members. Understand.
Programming using C# for Teachers Introduction to Objects Reference Types Functions of Classes Attributes and Types to a class LECTURE 2.
Chapter 6 OOP: Creating Object-Oriented Programs Programming In Visual Basic.NET.
Object-Oriented Application Development Using VB.NET 1 Chapter 8 Understanding Inheritance and Interfaces.
Microsoft Visual Basic 2008 CHAPTER ELEVEN Multiple Classes and Inheritance.
CSCI 1100/1202 April 1-3, Program Development The creation of software involves four basic activities: –establishing the requirements –creating.
CIS162AD Inheritance Part 3 09_inheritance.ppt. CIS162AD2 Overview of Topics  Inheritance  Virtual Methods used for Overriding  Abstract Classes and.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 26 - Java Object-Based Programming Outline 26.1Introduction.
Application development with Java Lecture 21. Inheritance Subclasses Overriding Object class.
Introduction to Object-Oriented Programming Lesson 2.
Coming up: Inheritance
Object Oriented Programming. OOP  The fundamental idea behind object-oriented programming is:  The real world consists of objects. Computer programs.
Presented by Ted Higgins, SQL Server DBA An Introduction to Object – Oriented Programming.
Class Inheritance SWE 344 Internet Protocols & Client Server Programming.
Object orientation and Packaging in Java Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify.
1 C# - Inheritance and Polymorphism. 2 1.Inheritance 2.Implementing Inheritance in C# 3.Constructor calls in Inheritance 4.Protected Access Modifier 5.The.
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
Lecture 2 Intro. To Software Engineering and Object-Oriented Programming (2/2)
Object-Oriented Programming: Classes and Objects.
Polymorphism and access control. RHS – SOC 2 What is polymorphism? In general: the ability of some concept to take on different forms In Java: the ability.
Modern Programming Tools And Techniques-I
Web Design & Development Lecture 9
Chapter - 4 OOP with C# S. Nandagopalan.
Object-Oriented Programming Concepts
Classes (Part 1) Lecture 3
Lecture 12 Inheritance.
2.7 Inheritance Types of inheritance
Inheritance and Polymorphism
Module 5: Common Type System
OOP What is problem? Solution? OOP
PRINCIPALES OF OBJECT ORIENTED PROGRAMMING
Object Oriented Analysis and Design
OOP’S Concepts in C#.Net
The University of Texas Rio Grande Valley
Polymorphism and access control
CSCI 3328 Object Oriented Programming in C# Chapter 9: Classes and Objects: A Deeper Look UTPA – Fall 2012 This set of slides is revised from lecture.
Object-Oriented Programming: Inheritance
Presentation transcript:

Section 3: Component/Object Oriented Programming, Events, and Delegates in.NET Jim Fiddelke, Greenbrier & Russel

Section 3: Component/Object Oriented Programming with.NET Component-Oriented Versus Object-Oriented Programming Encapsulation Polymorphism Inheritance Overloading Interfaces Events Delegates

Component-Oriented Versus Object-Oriented Programming Component is an overused term Unlike traditional object-oriented classes, every.NET class is a binary component. Therfore our defintion of a component is : “a component is a.NET class” A component is responsible for exposing business logic to an entity that uses the component (the “client”) While.NET doesn’t enforce interface-based programming, you should strive to do so whenever possible. Component-Oriented vs. Object-Oriented programming really boils down to creating building blocks vs. monolithic applications. The contracts that define how the building blocks are to interact are the interfaces. –component programming emphasizes interfaces –object-oriented emphasizes inheritance – poor way to reuse.

Component-Oriented Versus Object-Oriented Programming To use a component the client needs to know only the interface definition and be able to access a binary component that implements that interfaces (the “server”). Why: scalability, availability, throughput Emphasis on interfaces An interface is simply a contract for behavior that defines the members a class should implement. It does not specify details on how it should be implemented. More on interfaces later

Components provide “location transparency” – there is nothing in the client’s code pertaining to where the object executes. Machine A Process 1 Object Client Process 2 Object Machine B Process 1 Object WWW WWW Machine C Process 1 Object

Recall… –Classes are blueprints for objects –Objects are composed of members –Members include: data –fields –properties methods – actions the object can perform events – notifications an object receives or sends

Polymorphism “Polymorphism is the ability of different classes to provide different implementations of the same public interfaces.”

Encapsulation “One of the most important principles of objects is that they enclose functionality and data while providing an interface with which to interact with other objects. An object's users don't care how the object does what it does; they just want it done well and to have a simple interface. This "black box" characteristic of objects is known as encapsulation. “

Overloading Members Members include: –data fields properties –methods – actions the object can perform –events – notifications an object receives or sends Overloading allows you to create multiple members with the same name Each member that shares a name must have a different signature Most common in methods. C# allows operator overloading.

Overloading: let’s talk about inheritance first… Both C# and VB.NET can use class-based inheritance In.NET a class can derive from at most one other class However, a class can implement multiple interfaces

Class-based Inheritance Class-based Inheritance C#: class Account { //some code } class Checking : Account { //add some functionality to base.Account } VB.NET: Class Account ‘some code End Class Class Checking Inherits Account ‘ Add some functionality to MyBase.Account End Class

public class ParentClass { public ParentClass() { Console.WriteLine("Parent Constructor."); } public void print() { Console.WriteLine("I'm a Parent Class."); } public class ChildClass : ParentClass { public ChildClass() { Console.WriteLine("Child Constructor."); } public static void Main() { ChildClass child = new ChildClass(); child.print(); } Class-based Inheritance Class-based Inheritance

Class Inheritance Demo

Overloading Again, “Overloading means that several methods have the same name but different signatures”… C# class Account { public void MakeDeposit(int Amount) { } public void MakeDeposit(int Amount, int AmountAvailable) { } } VB.NET Class Account Sub MakeDeposit(ByVal Amount As Integer) End Sub Sub MakeDeposit(ByVal Amount As Integer, _ ByVal AmountAvailable As Integer) End Sub End Class

Overloading Both C# and VB.NET have a mechanism by which you can mark a function as virtual in the base class, and then override the method in the derived class. class Account { public virtual void MakeDeposit(int Amount) { } class Checking : Account { public override void MakeDeposit(int Amount) { } In VB.NET: virtual = Overridable override = Overrides

class Account { public virtual void MakeDeposit(int Amount) { } class Checking : Account { public override sealed void MakeDeposit(int Amount) { } class SuperChecking : Checking { //*** this is illegal *** public override void MakeDeposit(int Amount) { } In VB.NET: sealed = NotOverridable And you can also mark a class (or member) as “sealed”- it cannot be used as a base class…

What about the opposite – you want to create a class or member that you must inherit from… abstract class Account { public void ReportInfo() { System.Console.WriteLine( “Account is of type “ + AccountType); } public abstract string AccountType { get;}; //“ReadOnly” in VB.NET } class Checking : Account { public override string AccountType { get { return “Checking”; } VB.NET: class abstract = MustInherit property abstract = MustOverride override = Overrides

Interfaces interface IParentInterface { void ParentInterfaceMethod(); } interface IMyInterface : IParentInterface { void MethodToImplement(); } class InterfaceImplementer : IMyInterface { static void Main() { InterfaceImplementer iImp = new InterfaceImplementer(); iImp.MethodToImplement(); iImp.ParentInterfaceMethod(); } public void MethodToImplement() { Console.WriteLine("MethodToImplement() called."); } public void ParentInterfaceMethod() { Console.WriteLine("ParentInterfaceMethod() called."); }

Interfaces Demo

Class Projects - feel free to work with your neighbor -