These materials where developed by Martin Schray

Slides:



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

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.
Object-Oriented Application Development Using VB.NET 1 Chapter 8 Understanding Inheritance and Interfaces.
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.
More about classes and objects Classes in Visual Basic.NET.
Road Map Introduction to object oriented programming. Classes
Compunet Corporation1 Programming with Visual Basic.NET Inheritance Lecture # 10 Tariq Ibn Aziz.
VB Classes ISYS 573. Object-Oriented Concepts Abstraction: –To create a model of an object, for the purpose of determining the characteristics (properties)
VB Classes ISYS 512. Adding a Class to a Project Project/Add Class –*** MyClass is a VB keyword. Steps: –Adding properties Declare Public variables in.
Object-Oriented Programming in Visual Basic.NET. Overview Defining Classes Creating and Destroying Objects Inheritance Interfaces Working with Classes.
Object-Oriented Programming: Inheritance
Object Based Programming. Summary Slide  Instantiating An Object  Encapsulation  Inheritance  Polymorphism –Overriding Methods –Overloading vs. Overriding.
Lecture 8 Inheritance Richard Gesick. 2 OBJECTIVES How inheritance promotes software reusability. The concepts of base classes and derived classes. To.
Chapter 8 More Object Concepts
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.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Programming Pillars Introduction to Object- Oriented Programming.
Lecture Set 11 Creating and Using Classes Part B – Class Features – Constructors, Methods, Fields, Properties, Shared Data.
Tuc Goodwin  Object and Component-Oriented Programming  Classes in C#  Scope and Accessibility  Methods and Properties  Nested.
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.
Classes In C++ 1. What is a class Can make a new type in C++ by declaring a class. A class is an expanded concept of a data structure: instead of holding.
 Classes in c++ Presentation Topic  A collection of objects with same properties and functions is known as class. A class is used to define the characteristics.
Visual C# 2012 for Programmers © by Pearson Education, Inc. All Rights Reserved.
Object-Oriented Application Development Using VB.NET 1 Chapter 8 Understanding Inheritance and Interfaces.
Microsoft Visual Basic 2008 CHAPTER ELEVEN Multiple Classes and Inheritance.
Programming with Microsoft Visual Basic 2012 Chapter 11: Classes and Objects.
Copyright © 2002 W. A. Tucker1 Chapter 10 Lecture Notes Bill Tucker Austin Community College COSC 1315.
Programming With Java ICS201 University Of Ha’il1 Chapter 7 Inheritance.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Classes, Interfaces and Packages
Object-Oriented Programming: Inheritance and Polymorphism.
Chapter 2 11/18/2015 © by Pearson Education, Inc. All Rights Reserved. Lect9 GC 2011.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
Object-Oriented Programming: Classes and Objects Chapter 1 1.
JAVA ACCESS MODIFIERS. Access Modifiers Access modifiers control which classes may use a feature. A classes features are: - The class itself - Its member.
Object-Oriented Programming: Classes and Objects.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Class Inheritance Part II: Overriding and Polymorphism Corresponds with Chapter 10.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Topic: Classes and Objects
Object-Oriented Programming: Classes and Objects
Final and Abstract Classes
Inheritance and Polymorphism
Microsoft Visual Basic 2005: Reloaded Second Edition
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Method.
Object-Oriented Programming: Classes and Objects
Object-Oriented Programming: Inheritance
Object Oriented Programming
OOP’S Concepts in C#.Net
Object-Oriented Programming: Inheritance
Corresponds with Chapter 7
Lecture 22 Inheritance Richard Gesick.
Classes & Objects: Examples
Java – Inheritance.
Object-Oriented Programming: Inheritance
Object-Oriented Programming: Classes and Objects
Tonga Institute of Higher Education
Object-Oriented Programming: Inheritance and Polymorphism
Object-Oriented Programming: Inheritance
CIS16 Application Development and Programming using Visual Basic.net
CIS 199 Final Review.
Classes & Objects A deeper Look Chapter 10 & 11
Final and Abstract Classes
Object-Oriented Programming: Inheritance
Presentation transcript:

Martin Schray http://www.martinschray.com martin@martinschray.com 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 like to suggest corrections or enhancements please drop me a note at martin@martischray.com Martin Schray http://www.martinschray.com martin@martinschray.com

VB .NET - Using Objects & basics about classes Copyright © Martin Schray 1997- 2003

VB .NET Classes Uses of a class they can be used to define abstract data types Data is protected or hidden inside a class Class can be used to derive another class New classes derived from existing class will inherit the data and methods already defined public class MyClass // class members End Class

Declaring a class [attributes] [Class Modifiers] class ClassName [inherits SuperClass] [implements Interface] //list of variables and methods declarations End Class

Class Access Modifiers (page x) Public Optional. Public access. There are no restrictions on the use of public entities. Private Optional. Private access. A private entity is accessible only within its declaration context, including any nested entities. Protected (only applies to class members) Optional. Protected access. They are accessible only from within their own class or from a derived class. Protected access can be specified only on members of classes (including inner classes). It is not a superset of friend access. Friend Optional. Friend access. Only within the program that contains the entity declaration. Classes that do not specify an access modifier are declared as Friend by default. Protected Friend Optional. Entities declared with the Protected Friend modifiers have the union of protected and friend accessibility.

Other Class Modifiers Shadows (only applies to class members) Optional. Indicates that this class shadows an identically named programming element in a base class. You can shadow any kind of declared element with any other kind. A shadowed element is unavailable in the derived class that shadows it MustInherit Optional. Indicates that non-shared members of the Class can only be accessed via derived classes. Instances of must-inherit classes cannot be created. NotInheritable Optional. Indicates that the Class is a class from which no further inheritance is allowed.

Class Modifiers Only one modifier from each of the following groups can be used in a method declaration public, private, friend, protected friend <empty – gives you the default of friend> mustInherit, notIheritable

Class example public class point private x,y as integer public sub move(dx as Integer, dy as integer) x += dx; y += dy; End Sub end class

Class Terms All variables and functions of a class are called members of the class Member functions of a class are also called methods of the class or simply methods A object is not created until it is instantiated with the new keyword

Initializing Instance Variables Instance variables are initialized automatically Instance variables can also be assigned a default value

New Subroutine (Constructors) New Methods are member functions which are automatically executed when a class is instantiated The method has the name new ?New are invoked after initial default members are initialize ?No argument constructor is provided when no other constructor are provided

New Subroutine (Constructors) There can multiple constructors (as long a signature differs)

Functions (return a value) A class’s method typically contains the code that understands and manipulates an object’s state. Syntax for method declaration follows [ <attrlist> ] [{ Overloads | Overrides | Overridable | NotOverridable | MustOverride | Shadows | Shared }] [{ Public | Protected | Friend | Protected Friend | Private }] Function name[(arglist)] [ As type ] [ Implements interface.definedname ] [ statements ] [ Exit Function ] [ statements ] End Function

Function Declaration Method declaration perform three main tasks: determine who may call the method (public, private…) determine what the method may receive as arguments (parameters) determine what and if the method returns VB. Net does not allow a variable number of arguments like c++

Subroutine (no return value) Like a function, but with NO return value [ <attrlist> ] [{ Overloads | Overrides | Overridable | NotOverridable | MustOverride | Shadows | Shared }] [{ Public | Protected | Friend | Protected Friend | Private }] Sub name [(arglist)] [ Implements interface.definedname ] [ statements ] [ Exit Sub ] [ statements ] End Sub

Sub Declaration Method declaration perform three main tasks: determine who may call the method (public, private…) determine what the method may receive as arguments (parameters) NO RETURN TYPE VB. Net does not allow a variable number of arguments like c++

Function and Sub Modifiers Public Optional. Public access. There are no restrictions on the accessibility of public procedures. Protected Optional. Protected access. They are accessible only from within their own class or from a derived class. Protected access can be specified only on members of classes. It is not a superset of friend access. Friend Optional. Procedures declared with the Friend keyword have friend access. They are accessible from within the program that contains their declaration and from anywhere else in the same assembly. Protected Friend Optional. Protected Friend keywords have the union of protected and friend access. They can be used by code in the same assembly, as well as by code in derived classes. Protected friend access can be specified only on members of classes. Private Optional. Private access. They are accessible only from within their declaration context, including from members of any nested types such as procedures.

Function & sub Modifiers Overloads Optional. This Sub procedure overloads one or more procedures defined with the same name in a base class. The argument list in this declaration must be different from the argument list of every overloaded procedure. Overrides Optional. Indicates that this Sub procedure overrides an identically named procedure in a base class.

Function and Sub Modifiers Overridable Optional. Indicates that this Sub procedure can be overridden by an identically named procedure in a derived class. NotOverridable Optional. Indicates that this Sub procedure cannot be overridden in a derived class. MustOverride Optional. Indicates that this Sub procedure is not implemented in this class and must be implemented in a derived class for that class to be creatable. Shadows Optional. A shadowed element is unavailable in the derived class that shadows it.

Method Modifiers Only one modifier from each of the following groups can be used in a method declaration public, protected, private, friend, protected friend<empty> Overloads or shadows Overrideable, noteoverridable, Mustoverride

Hello Class public class Hello ‘ class level variables go here private shared count as interger = 0 private shared const msg as String = “I have been called this many times ”; public sub new() // constuctor count++; // increment count by one End Sub public sub Message() System.Console.writeln(msg & count); end sub End Class

Testing Classes Module Module1 Sub Main() Dim c As New FirstClass() FirstClass.SharedTest() c.test() End Sub End Module Public Class FirstClass Public Sub test() System.Console.WriteLine("test") Public Shared Sub SharedTest() System.Console.WriteLine("Shared test") End Class