Module 4: Implementing Object-Oriented Programming Techniques in C#

Slides:



Advertisements
Similar presentations
OOP Abstraction Classes Class Members: Properties & Methods Instance (object) Encapsulation Interfaces Inheritance Composition Polymorphism Using Inheritance.
Advertisements

ITF11006.NET Inheritance. Classes and Inheritance Constructors and Inheritance Modifiers Interfaces Operators.
Module 8 “Polymorphism and Inheritance”. Outline Understanding Inheritance Inheritance Diagrams Constructors in Derived Classes Type Compatibility Polymorphism.
Inheritance Definition Relationships Member Access Control Data Encapsulation Overloading vs. Overriding Constructors & Destructors.
Objectives Introduction to Inheritance and Composition (Subclasses and SuperClasses) Overriding (and extending), and inheriting methods and constructors.
CS 2511 Fall Features of Object Oriented Technology  Abstraction Abstract class Interfaces  Encapsulation Access Specifiers Data Hiding  Inheritance.
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.
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 using Java
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Taken from slides of Starting Out with C++ Early Objects Seventh Edition.
Lecture 8 Inheritance Richard Gesick. 2 OBJECTIVES How inheritance promotes software reusability. The concepts of base classes and derived classes. To.
Module 7: Object-Oriented Programming in Visual Basic .NET
Object Oriented Programming: Java Edition By: Samuel Robinson.
CS200 Algorithms and Data StructuresColorado State University Part 4. Advanced Java Topics Instructor: Sangmi Pallickara
Inheritance Building one object from another. Background Object-oriented programming is normally described has offering three capabilities Encapsulation:
Object-Oriented Programming. An object is anything that can be represented by data in a computer’s memory and manipulated by a computer program.
OOP: Encapsulation,Abstraction & Polymorphism. What is Encapsulation Described as a protective barrier that prevents the code and data being randomly.
Module 10: Inheritance in C#. Overview Deriving Classes Implementing Methods Using Sealed Classes Using Interfaces Using Abstract Classes.
Presented by Ted Higgins, SQL Server DBA An Introduction to Object – Oriented Programming.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
Comp1004: Inheritance II Polymorphism. Coming up Inheritance Reminder Overriding methods – Overriding and substitution Dynamic Binding Polymorphism –
1 Inheritance One of the goals of object oriented programming is code reuse. Inheritance is one mechanism for accomplishing code reuse. It allows us to.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Modern Programming Tools And Techniques-I
OOP: Encapsulation &Abstraction
Object-Oriented Programming Concepts
Classes (Part 1) Lecture 3
Advanced Java Topics Chapter 9
Classes and Inheritance
2.7 Inheritance Types of inheritance
Object-Oriented Programming (OOP) Lecture No. 45
Inheritance and Polymorphism
One class is an extension of another.
Module 5: Common Type System
Object-Oriented Programming
Review: Two Programming Paradigms
Inheritance AKEEL AHMED.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
Object Oriented Analysis and Design
Chapter 4: Creating Objects in C#
OOP’S Concepts in C#.Net
CSC 205 Java Programming II
One class is an extension of another.
Inheritance Basics Programming with Inheritance
Lecture 22 Inheritance Richard Gesick.
Inheritance, Polymorphism, and Interfaces. Oh My
Abstract Classes AKEEL AHMED.
Module 3: Creating Objects in C#
Interfaces.
Advanced Programming Behnam Hatami Fall 2017.
Computer Programming with JAVA
Inheritance Inheritance is a fundamental Object Oriented concept
Fundaments of Game Design
Chapter 9 Carrano Chapter 10 Small Java
Workshop for Programming And Systems Management Teachers
Overview of C++ Polymorphism
Inheritance and Polymorphism
By Rajanikanth B OOP Concepts By Rajanikanth B
CIS 199 Final Review.
Object Oriented Analysis and Design
Object-Oriented PHP (1)
Chapter 11 Inheritance and Encapsulation and Polymorphism
Jim Fawcett CSE687 – Object Oriented Design Spring 2014
CSG2H3 Object Oriented Programming
Computer Science II for Majors
CMSC 202 Lesson 17 Inheritance II.
Presentation transcript:

Module 4: Implementing Object-Oriented Programming Techniques in C#

Overview Designing Objects Using Inheritance Using Polymorphism

Lesson: Designing Objects What Are the Benefits of Object-Oriented Programming? What Is Encapsulation? What Are Properties?

What Are the Benefits of Object-Oriented Programming? Structured Design Tendencies Object-Oriented Tendencies Process-Centered Object-Centered 1 Hides Data Reveals Data 2 3 Modular Units Single Unit 4 Reusable One-Time Use Ordered Algorithm Nonordered Algorithm 5

What Is Encapsulation? Grouping related pieces of information and processes into self-contained unit Makes it easy to change the way things work under the cover without changing the way users interact Hiding internal details Makes your object easy to use

What Are Properties? Properties are methods that protect access to class members private int animalWeight; public int Weight { get { return animalWeight; } set { animalWeight = value;

Practice: Writing and Using Properties Hands-on Practice In this practice, you will write and use properties 10 min

Lesson: Using Inheritance What Is Inheritance? How to Create a Derived Class How to Call a Base Constructor from a Derived Class How to Use a Sealed Class

What Is Inheritance? Inheritance specifies an is-a-kind-of relationship Derived classes inherit properties and methods from a base class, allowing code reuse Derived classes become more specialized Base Class Animal Elephant Cat Derived Classes

How to Create a Derived Class public class Animal { protected bool IsSleeping; public void Sleep() { } public void Eat() { } } public class Lion : Animal { public void StalkPrey() { } ... Lion adoptedLion = new Lion(); adoptedLion.StalkPrey(); adoptedLion.Eat();

How to Call a Base Constructor from a Derived Class The base keyword is used in derived classes to specify a non-default base class constructor public class Animal { public Animal(GenderType gender) { // . . . Console.WriteLine("Constructing Animal"); } public class Elephant : Animal { public Elephant(GenderType gender): base(gender) { //Elephant code Console.WriteLine("Constructing Elephant");

How to Use a Sealed Class You cannot derive from a sealed class Prevents the class from being overridden or extended by third parties public sealed class MyClass { // class members }

Practice: Creating a Derived Class Hands-on Practice In this practice, you will learn how to use base classes and derived classes 10 min

Lesson: Using Polymorphism What Is Polymorphism? How to Write Virtual Methods How to Use Base Class Members from a Derived Class What Are Abstract Methods and Classes?

What Is Polymorphism? Eat () Animal Objects Elephant Cat Mouse Method Called Eat () Behavior Eat Grass Eat Mouse Eat Cheese

How to Write Virtual Methods Virtual methods are used to define base class methods that you expect to be overridden in derived classes public class Animal { public virtual void Eat() { Console.WriteLine("Eat something"); } public class Cat : Animal { public override void Eat() { Console.WriteLine("Eat small animals"); Base Class Derived Class Animal Cat Virtual Method Override Method Eat () Eat () What Happens What Happens Eat Something Eat Mouse

How to Use Base Class Members from a Derived Class The base keyword is used to call a method in the base class from a derived class public class Cat : Animal { public override void Eat() { base.Eat(); Console.WriteLine("Eat small animals"); }

What Are Abstract Methods and Classes? An abstract class is a generic base class Contains an abstract method that must be implemented by a derived class An abstract method has no implementation in the base class Can contain non-abstract members public abstract class Animal { public abstract void Eat(); public abstract Group PhylogenicGroup { get; } }

Practice: Using Polymorphism Hands-on Practice In this practice, you will implement the Animal class as an abstract class, and modify the derived classes so that they override the abstract methods in the Animal class 1 hour

Review Designing Objects Using Inheritance Using Polymorphism

Lab 4.1: Creating Classes in C# Exercise 1: Creating the Bank Account Objects 1 hour