More about classes and objects Classes in Visual Basic.NET.

Slides:



Advertisements
Similar presentations
Final and Abstract Classes
Advertisements

OO Programming in Java Objectives for today: Constructors Method Overriding & Overloading Encapsulation.
Abstract Classes We often define classes as subclasses of other classes – First, define the superclass – In some cases, a superclass may not have enough.
Module 8 “Polymorphism and Inheritance”. Outline Understanding Inheritance Inheritance Diagrams Constructors in Derived Classes Type Compatibility Polymorphism.
Advanced Object Oriented Concepts Tonga Institute of Higher Education.
Object-Oriented Application Development Using VB.NET 1 Chapter 8 Understanding Inheritance and Interfaces.
CIS162AD Inheritance 09_inheritance.ppt. CIS162AD2 Overview of Topics  Inheritance  Virtual Methods used for Overriding  Constructors & Inheritance.
Chapter 11: Implementing Inheritance and Association Visual Basic.NET Programming: From Problem Analysis to Program Design.
Objectives Introduction to Inheritance and Composition (Subclasses and SuperClasses) Overriding (and extending), and inheriting methods and constructors.
12-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Encapsulation, Inheritance & Interfaces CSE 115 Spring 2006 February 27, March 1 & 3, 2006.
1 Lecture 06(Abstract Classes)Lecture 9 Abstract Classes Overview  Abstract Classes: A Definition.  Declaring Abstract Classes.  Abstract Methods: A.
1 Evan Korth New York University Inheritance and Polymorphism Professor Evan Korth New York University.
Compunet Corporation1 Programming with Visual Basic.NET Inheritance Lecture # 10 Tariq Ibn Aziz.
CPSC150 Interfaces Chapter CPSC150 Inheritance Review No different than any other class. Has no access to or information about subclasses class.
1 Evan Korth New York University Inheritance and Polymorphism Professor Evan Korth New York University.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Chapter 13 Polymorphism is-a relationships Interfaces.
Object-Oriented Application Development Using VB.NET 1 Chapter 8 Understanding Inheritance and Interfaces.
Chapter 7 - Generalization/Specialization and Inheritance1 Chapter 7 Generalization/Specialization and Inheritance.
Lecture 6: Polymorphism - The fourth pillar of OOP - 1.
Inheritance Chapter 14. What is inheritance?  The ability to create a class from another class, the “parent” class, extending the functionality and state.
Module 7: Object-Oriented Programming in Visual Basic .NET
Microsoft Visual Basic 2008 CHAPTER ELEVEN Multiple Classes and Inheritance.
Chapter 10: Writing Class Definitions Visual Basic.NET Programming: From Problem Analysis to Program Design.
Inheritance and Class Hierarchies Ellen Walker CPSC 201 Data Structures Hiram College.
1 Java Inheritance. 2 Inheritance On the surface, inheritance is a code re-use issue. –we can extend code that is already written in a manageable manner.
JAVA WORKSHOP SESSION – 3 PRESENTED BY JAYA RAO MTech(CSE) NEWTON’S INSTITUTE OF ENGINEERING 1.
Inheritance - Polymorphism ITI 1121 Nour El Kadri.
These materials where developed by Martin Schray. Please feel free to use and modify them for non-commercial purposes. If you find them useful or would.
Inheritance Chapter 10 Programs built from objects/instances of classes An O.O. approach – build on earlier work. Use classes in library and ones you have.
1 Lecture 6: Polymorphism - The fourth pillar of OOP -
Object-Oriented Application Development Using VB.NET 1 Chapter 8 Understanding Inheritance and Interfaces.
Java Programming Dr. Randy Kaplan. Abstract Classes and Methods.
Microsoft Visual Basic 2008 CHAPTER ELEVEN Multiple Classes and Inheritance.
8. Inheritance “Is-a” Relationship. Topics Creating Subclasses Overriding Methods Class Hierarchies Abstract Class Inheritance and GUIs The Timer Class.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Inheritance Objectives: Creating new classes from existing classes The protected modifier Creating class hierarchies Abstract classes Indirect visibility.
Programming With Java ICS201 University Of Ha’il1 Chapter 7 Inheritance.
Object Oriented Programming
Chapter 10: Introduction to Inheritance. Objectives Learn about the concept of inheritance Extend classes Override superclass methods Call constructors.
Coming up: Inheritance
© 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.
Basic Concepts of OOP.  Object-Oriented Programming (OOP) is a type of programming added to php5 that makes building complex, modular and reusable web.
CompSci Reading from Files  import java.io.File;  Declare a file File fileOfCats = new File(”cats.txt”);  Use file – pass it as an argument to.
Object-Oriented Programming: Inheritance and Polymorphism.
Chapter 2 11/18/2015 © by Pearson Education, Inc. All Rights Reserved. Lect9 GC 2011.
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.
CSC 205 Programming II Lecture 4 Abstract Class. The abstract keyword indicate that a class is not instantiable Defining a type which will be specialized.
SUBCLASSES - JAVA. The Purpose of Subclasses Class Farm String getOwner() void setOwner(String s) int getSize() void setSize(int s) Class DairyFarm String.
CS 116 Object Oriented Programming II Acknowledgement: Contains materials provided by George Koutsogiannakis and Matt Bauer.
Inheritance a subclass extends the functionality of a superclass a subclass inherits all the functionality of a superclass don't reinvent the wheel – "stand.
OOP: Encapsulation &Abstraction
Final and Abstract Classes
Inheritance and Polymorphism
One class is an extension of another.
Microsoft Visual Basic 2005: Reloaded Second Edition
Polymorphism.
Road Map Inheritance Class hierarchy Overriding methods Constructors
One class is an extension of another.
Chapter 11 – Object-Oriented Programming
OBJECT ORIENTED PROGRAMMING II LECTURE 8 GEORGE KOUTSOGIANNAKIS
Polymorphism CT1513.
Interfaces.
Java – Inheritance.
Object-Oriented Programming: Inheritance and Polymorphism
Object-Oriented Programming: Inheritance
Final and Abstract Classes
Lecture 6: Polymorphism
INTERFACES Explained By: Sarbjit Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
Presentation transcript:

More about classes and objects Classes in Visual Basic.NET

We have seen... Basics of OOP terminology Object Class Method Overloading Overriding Basics of OOP concepts Abstraction Polymorphism Encapsulation Inheritance How to draw class diagrams

Shape, Circle and Rectangle Shape x, y : Integer draw() : String Circle r : Integer Rectangle h, w : Integer

Creating classes in VB.NET Classes are written in files, in a similar way than forms. They are added using the Add class... item in the Project menu. Involves... setting up the variables implementing a constructor implementing the methods required

Code for Shape Public Class Shape Protected x, y As Integer Public Sub New() x = 12 y = 30 End Sub Public Function draw() draw = "I am a nice shape" End Function End Class

Abstract classes Cannot be instantiated Only classes that extend them can be instantiated Used as holders for their subclasses VB.NET uses keyword "MustInherit" Public MustInherit Class Shape

Creating subclasses Two options: New file (through Add class...) Same file Subclasses might hold variables of their own VB.NET uses keyword "Inherits" Public Class Circle Inherits Shape

Overriding methods A subclass can redefine methods that appear in its parent Circle can give a new implementation to inherited method draw() VB.NET uses the keyword "Overrides" Public Overrides Function draw()

Abstract methods Sometimes the parent class just "mentions" a method, without providing an implementation VB.NET uses keyword "MustOverride" Any class with at least one abstract method must be declared abstract It is a good idea to make the method draw() in Shape abstract

Abstract Shape Public MustInherit Class Shape Protected x, y As Integer Public Sub New() x = 12 y = 42 End Sub Public MustOverride Function draw() End Class