Presented by Ted Higgins, SQL Server DBA An Introduction to Object – Oriented Programming.

Slides:



Advertisements
Similar presentations
C++ Classes & Data Abstraction
Advertisements

Module 8 “Polymorphism and Inheritance”. Outline Understanding Inheritance Inheritance Diagrams Constructors in Derived Classes Type Compatibility Polymorphism.
CS 211 Inheritance AAA.
Inheritance Inheritance Reserved word protected Reserved word super
Objectives Introduction to Inheritance and Composition (Subclasses and SuperClasses) Overriding (and extending), and inheriting methods and constructors.
9. Inheritance 9.1 Subclasses 9.2 Polymorphism 9.3 Abstract Classes 9.4 Modifiers and Access 9.6 Object-Oriented Design with Use Cases and Scenarios.
ITEC200 – Week03 Inheritance and Class Hierarchies.
Inheritance. Extending Classes It’s possible to create a class by using another as a starting point  i.e. Start with the original class then add methods,
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 8.1 – 8.5.
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.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
Introduction to Data Structures, Spring 2007 Slide- 1 California State University, Fresno Introduction to Data Structure Object Oriented Programming Concepts.
CS 2511 Fall  Abstraction Abstract class Interfaces  Encapsulation Access Specifiers Data Hiding  Inheritance  Polymorphism.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Inheritance. © 2004 Pearson Addison-Wesley. All rights reserved 8-2 Inheritance Inheritance is a fundamental object-oriented design technique used to.
Programming Languages and Paradigms Object-Oriented Programming.
Chapter 4 Inheritance Bernard Chen Spring Objective IS-A relationships and the allowable changes for derived classes The concept of polymorphism.
Chapter 6 Class Inheritance F Superclasses and Subclasses F Keywords: super F Overriding methods F The Object Class F Modifiers: protected, final and abstract.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
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.
Overview of Previous Lesson(s) Over View  OOP  A class is a data type that you define to suit customized application requirements.  A class can be.
CSM-Java Programming-I Spring,2005 Objects and Classes Overview Lesson - 1.
Module 7: Object-Oriented Programming in Visual Basic .NET
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
BIM313 – Advanced Programming Techniques Object-Oriented Programming 1.
Inheritance and Class Hierarchies Ellen Walker CPSC 201 Data Structures Hiram College.
C# Programming Fundamentals of Object-Oriented Programming Fundamentals of Object-Oriented Programming Introducing Microsoft.NET Introducing Microsoft.NET.
Programming Pillars Introduction to Object- Oriented Programming.
Tuc Goodwin  Object and Component-Oriented Programming  Classes in C#  Scope and Accessibility  Methods and Properties  Nested.
C# F 1 CSC 298 Object Oriented Programming (Part 1)
Chapter 3 Inheritance and Polymorphism Goals: 1.Superclasses and subclasses 2.Inheritance Hierarchy 3.Polymorphism 4.Type Compatibility 5.Abstract Classes.
Programming in Java CSCI-2220 Object Oriented Programming.
Introducing Allors Applications, Tools & Platform.
CS170 ygao JAVA, C4Slide 1. CS170 ygao JAVA, C4Slide 2.
1 OOP - An Introduction ISQS 6337 John R. Durrett.
Object Oriented Programming
Chapter 10: Introduction to Inheritance. Objectives Learn about the concept of inheritance Extend classes Override superclass methods Call constructors.
PROGRAMMING IN C#. Collection Classes (C# Programming Guide) The.NET Framework provides specialized classes for data storage and retrieval. These classes.
Lecture 8: Object Oriented Programming. What is a Programming Object? An object is an instance of a class. A class is a template for an object. Everything's.
Introduction to Object-Oriented Programming Lesson 2.
Coming up: Inheritance
Polymorphism, Virtual Methods and Interfaces Version 1.1.
Interfaces F What is an Interface? F Creating an Interface F Implementing an Interface F What is Marker Interface?
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
© 2007 Lawrenceville Press Slide 1 Chapter 9 Inheritance  One class is an extension of another.  Allows a class to define a specialized type of an existing.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
Classes, Interfaces and Packages
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.
Recap Introduction to Inheritance Inheritance in C++ IS-A Relationship Polymorphism in Inheritance Classes in Inheritance Visibility Rules Constructor.
YG - CS Concept of Encapsulation What is encapsulation? - data and functions/methods are packaged together in the class normally.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
C# Fundamentals An Introduction. Before we begin How to get started writing C# – Quick tour of the dev. Environment – The current C# version is 5.0 –
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Lecture 12 Inheritance.
Inheritance and Polymorphism
Module 5: Common Type System
Object-Oriented Programming
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Object-Orientated Programming
OOP’S Concepts in C#.Net
Java Programming Language
Lecture 22 Inheritance Richard Gesick.
Abstract Classes AKEEL AHMED.
Fundaments of Game Design
By Rajanikanth B OOP Concepts By Rajanikanth B
CIS 199 Final Review.
C++ Object Oriented 1.
Presentation transcript:

Presented by Ted Higgins, SQL Server DBA An Introduction to Object – Oriented Programming

A high-level overview of Object Oriented Programming Code demos of the concepts – again high-level, basic stuff Some of the benefits of OOA/OOP Why it may, or may not, be for you: the C or COBOL developer I’ll try and stay on track with the concept of OOP design and what it is versus concentrating on the OO language – C# in this case Code examples are not designed for production! While I have attempted to present the code demos in a clear and concise manner, they are just that, demos! Introduction

Evolution of Programming Languages

C# Application Creation

C# Application Execution

The.NET Framework

What is OOP?

Key Concepts of OOP

Concepts We Will Explore

What is an Object

A Simple Example Object vs. Procedural:

What is a Class A Class defines an Object A Class has Fields/Properties that define it (its State) A Class has Methods that define its behavior Vehicle Lets add some fields to our Vehicle class private int vehicleID private string propulsion Behavior is handled by Methods Properties set and retrieve the private data in the class (note: private and public are part of encapsulation) public vehicle() public vehicle(x, y) VehicleID {get; set;} Propulsion {get; set;} Virtual void GetValues( ); Constructors are used to initialize the Object at creation time

Coding a (Base) Class Lets code a class in C# 1.Create and name the class 2.Create it’s members 3.Create a custom constructor 4.Create methods 5.Create Properties public class Vehicle { private int _vehicleID; private string _propulsion; public Vehicle (ID, propulsion) { this._vehicleID = ID; this._propulsion = propulsion; } public virtual string GetValues () { Console.Writeline(“ID: {0}, Propulsion: {1}”, _vehicleID, _propulsion ); } public int VehicleID { get { return _vehicleID; } set { _vehicleID = value; } } } // end class Vehicle

Instantiating an Object Lets create a Vehicle object in C# 1.Create a reference variable of type 2.Instantiate (create) the object using the new keyword 3.Access fields, properties and methods using the dot operator Vehicle myCar; myCar = new Vehicle( ); myCar.VehicleID = 2; myCar.Propulsion = “Turbo V6”; myCar.GetInformation( ); The default constructor for the Vehicle class is called here

Encapsulation Defined Encapsulation keeps private properties from being accessed by Objects created outside of the class Private, Protected, and Public are access modifiers Private members may only be accessed by Objects of the class Public members may be accessed by Objects outside of the class Vehicle private vehicleID private propulsion public vehicle() public vehicle(x, y) VehicleID {get; set;} Propulsion {get; set;} void GetValues ( )

Inheritance Defined Inheritance allows us to build a Class/Object Hierarchy We start by designing a Base Class, with Properties, Fields and Methods A Class may then be derived from the Base Class, Inherits all of that Classes members, and may add additional members as necessary to refine the object Vehicle Automobile Airplane Is-A -vehicleID - propulsion -vehicleID - propulsion -vehicleID - propulsion Base Class Derived Classes Inheritance is always based upon an “Is-A” relationship between base and derived classes

Inheritance Code Example The preceding Class would be coded in C# like this: Base Class - Vehicle Private Fields Public Method calls Private Methods Private Methods to set Private Fields Derived Class: Automobile Derived Class: Airplane

Inheritance Code Example 2 - Properties Base Class - Vehicle Private Fields Constructors Properties to set Private Fields Virtual Method – may be overridden by a derived class

Polymorphism Defined Polymorphism allows a Class to be used as more than one type: It’s defined type, Base type, or Interface type Overriding and Overloading of methods are used to implement polymorphism The correct method(s) are for the particular Object type are chosen at runtime Vehicle Automobile Airplane -vehicleID -propulsion + GetValues() -vehicleID -propulsion + GetValues() -vehicleID -propulsion + GetValues() Base Class Derived Classes The inherited GetValues method will be overridden by each derived class. The CLR will choose the correct implementation at runtime.

Polymorphism Implementation Polymorphism depends on Inheritance, you must use Inheritance to implement polymorphism Polymorphism is normally accomplished using one of the following: Abstract Classes Interfaces Characteristics of Abstract Classes: An abstract class must be marked as abstract You may not instantiate an abstract class An Abstract method has no implementation, the derived class must implement If you mark a method within a class as abstract, the entire class must be abstract All abstract methods within a abstract class must be implemented by the derived class An abstract method is automatically virtual, so that it may be overridden Characteristics of an Interface: An interface is declared using the interface keyword The interface provides only the return type and method name, no implementation All methods are inherently public, no access modifiers are allowed Interfaces can specify the signature for methods, properties and indexers Interfaces cannot define data members, constructors, or destructors No member can be declared “static” All members of an Interface must be implemented by the derived class

Advanced C# Techniques Design Patterns UML – Unified Modeling Language Advanced C# Techniques Some advanced C# (as well as other languages) techniques: Delegates Indexers Generics Nullable Types Interfaces Multiple Inheritance Check out this free.pdf booklet on C# and.NET from Charles Petzold:

Thank You!