Advanced Programming Using Visual Basic 2008

Similar documents
9/21/2010. Based on Chapter 2 in Advanced Programming Using Visual Basic.NET by Bradley and Millspaugh

Building Multitier Programs with Classes

Chapter 2. Building Multitier Programs with Classes The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill

Chapter 12. OOP: Creating Object- Oriented Programs. McGraw-Hill. Copyright 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved.

Chapter 12. OOP: Creating Object-Oriented Programs The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill

Chapter 02 Building Multitier Programs with Classes

Microsoft Visual Basic 2005: Reloaded

CIS Intro to Programming in C#

Public Class ClassName (naming: CPoint)

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity.

Chapter 5 Object-Oriented Programming

Object-Oriented Programming

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS313D: ADVANCED PROGRAMMING LANGUAGE

Lecture Contents CS313D: ADVANCED PROGRAMMING LANGUAGE

1. A Web Form created in Visual Basic can only be displayed in Internet Explorer. True False

CMSC 132: Object-Oriented Programming II

Object-Oriented Programming (OOP) Fundamental Principles of OOP

Introduction to OOP. Procedural Programming sequence of statements to solve a problem.

Inheritance, and Polymorphism.

Lecture Contents CS313D: ADVANCED PROGRAMMING LANGUAGE. What is Inheritance?

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS313D: ADVANCED PROGRAMMING LANGUAGE

CGS 2405 Advanced Programming with C++ Course Justification

CMSC 132: Object-Oriented Programming II

Object Orientated Analysis and Design. Benjamin Kenwright

Data Structures (list, dictionary, tuples, sets, strings)

VB.NET. Exercise 1: Creating Your First Application in Visual Basic.NET

Chapter 11 Object and Object- Relational Databases

Oops known as object-oriented programming language system is the main feature of C# which further support the major features of oops including:

Software Development. Modular Design and Algorithm Analysis

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

Compaq Interview Questions And Answers

Overview of OOP. Dr. Zhang COSC 1436 Summer, /18/2017

CS313D: ADVANCED PROGRAMMING LANGUAGE

I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination. June, 2015 BCS-031 : PROGRAMMING IN C ++

CS111: PROGRAMMING LANGUAGE II

Hierarchical inheritance: Contains one base class and multiple derived classes of the same base class.

Get Unique study materials from

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Inheritance and Polymorphism

M Introduction to Visual Basic.NET Programming with Microsoft.NET 5 Day Course

Data Abstraction. Hwansoo Han

Object Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix

Lecture 10 OOP and VB.Net


DEVELOPING OBJECT ORIENTED APPLICATIONS

Introduction to Object- Oriented Programming

Java Object Oriented Design. CSC207 Fall 2014

Chapter 6 Introduction to Defining Classes

PROGRAMMING LANGUAGE 2

Object-Oriented Programming

Module 6: Fundamentals of Object- Oriented Programming

2559 : Introduction to Visual Basic.NET Programming with Microsoft.NET

INTRODUCTION TO.NET. Domain of.net D.N.A. Architecture One Tier Two Tier Three Tier N-Tier THE COMMON LANGUAGE RUNTIME (C.L.R.)

What are the characteristics of Object Oriented programming language?

Chapter 12 Object-Oriented Programming. Starting Out with Games & Graphics in C++ Tony Gaddis

OVERRIDING. 7/11/2015 Budditha Hettige 82

Object Oriented Programming With Visual Basic.NET

Data Structures using OOP C++ Lecture 3

VB.NET Web : Phone : INTRODUCTION TO NET FRAME WORK

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE

JAVA MOCK TEST JAVA MOCK TEST II

CREATED BY: Muhammad Bilal Arslan Ahmad Shaad. JAVA Chapter No 5. Instructor: Muhammad Naveed

SEEM4570 System Design and Implementation. Lecture 11 From Design to Implementation

STRUCTURING OF PROGRAM

EMBEDDED SYSTEMS PROGRAMMING OO Basics

Object Oriented Programming. Assistant Lecture Omar Al Khayat 2 nd Year

What is Inheritance?

7. C++ Class and Object

G Programming Languages - Fall 2012

IT101. Inheritance, Encapsulation, Polymorphism and Constructors

VALLIAMMAI ENGINEERING COLLEGE

Paytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value

Chapter 12: How to Create and Use Classes

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

Framework Fundamentals


Programming II (CS300)

CS260 Intro to Java & Android 03.Java Language Basics

CS111: PROGRAMMING LANGUAGE II

Ch02. True/False Indicate whether the statement is true or false.

PART A : MULTIPLE CHOICE Circle the letter of the best answer (1 mark each)

ENCAPSULATION. private, public, scope and visibility rules. packages and package level access.

Object-Oriented Design (OOD) and C++

I101 Introduction to Informatics

(800) Toll Free (804) Fax Introduction to Java and Enterprise Java using Eclipse IDE Duration: 5 days

AN OVERVIEW OF C++ 1

Computer Science 306 Study Guide

Polymorphism 2/12/2018. Which statement is correct about overriding private methods in the super class?

CS111: PROGRAMMING LANGUAGE II. Lecture 1: Introduction to classes

CS111: PROGRAMMING LANGUAGE II

Interview Questions of C++

Programming II (CS300)

Introduction to Programming Using Java (98-388)

15CS45 : OBJECT ORIENTED CONCEPTS

Learning Objectives. C++ For Artists 2003 Rick Miller All Rights Reserved xli

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

STUDENT LESSON A20 Inheritance, Polymorphism, and Abstract Classes

Transcription:

Building Multitier Programs with Classes Advanced Programming Using Visual Basic 2008 The OOP Development Approach OOP = Object Oriented Programming Large production projects are created by teams Each team works on a part as a separate building block for the app In OOP development (and in ASP.NET) the building blocks are classes 2 Class A class is a blueprint for an object Includes properties Attributes Characteristics Includes methods Functions Operations Behaviors 3 1

Abstraction (OOP Terminology) A model of an object that determines Characteristics properties Behaviors methods UML = Unified Modeling Language 4 Encapsulation (OOP Terminology) Combine characteristics of an object along with its behaviors into one package Data hiding Properties and procedures are hidden Programmer controls exposure of properties and methods available to other objects 5 Inheritance (OOP Terminology) The ability to create a new class from an existing class The existing (original) class is called the base, superclass, or parent The inherited class is called the derived, subclass, or child A derived class has an is a relationship with its base class 6 2

Inheritance (OOP Terminology) Form is a frmmain person is a $$customer$$ Base class Superclass parent derived class Subclass child Public Class frmmain Inherits System.Windows.Forms.Form Object-Oriented Programming 7 Inheritance Supports Reusability Place common code in a base class Derived classes can call shared functions and properties of the base class Reusability creation of object functionality that may be used in multiple projects 8 Abstract Classes Created for specific use as a base class Cannot create instances of abstract classes Derived classes can call shared functions Derived class methods override methods in the base class An abstract class is a class created strictly for the purpose of inheritance 9 3

Multiple Inheritance from Base Class Person -Name -Address -Phone Employee -HireDate -Supervisor Customer -AvgPurchase Student -ID -BirthDate 10 Polymorphism (OOP Terminology) Methods with identical names have different implementations e.g., the Select method is different for radio buttons, check boxes, and list boxes Allows a single class to have more than one method with the same name but different argument lists Polymorphism is the ability to take on Multiple shapes or forms. 11 Reusable Objects Classes created may be used in multiple projects Example Microsoft Spell Checker 12 4

Multitier Applications Write components that can be replaced or modified without replacing or modifying other components Plug-in in new components to update or extend the application Applications designed as components that work together. Each component performs a service. Each service provides part of the necessary actions. 13 Multitier Applications Three-tier applications are popular Presentation tier Business tier Data tier 14 Multitier Applications User Services Business Services Data Services User Interface Forms Controls Menus Business Object Validation Calculations Business logic Business rules Data Retrieval Data storage 15 5

Multitier Applications Presentation tier the user interface You can change the method of delivery without changing the processing for the task 16 Multitier Applications Business tier class(es) that handle or manipulate the data Calculations Validation to enforce business ss rules Data tier retrieving and storing the data in a database 17 Create Your Own Class Instance Variables are used to hold characteristics (properties) of an object for use within the class Properties are created with Property procedures Sub procedures or function procedures are used to define behaviors (methods) 18 6

Creating Properties in a Class Declare all instance variables in a class as Private (encapsulation) Private variable values are only available to procedures in the class Reveal variable values as needed by exposing them as a property of the class 19 Private InstanceVariable As DataType Declare at module level [Public] Property PropertyName As DataType Get PropertyName = InstanceVariable or Return InstanceVariable End Get Set(ByVal Value As DataType) [statements, such as validation] InstanceVariable = Value End Set End Property Using a Property Procedure Procedure written with Set and Get keywords to pass values to and from private variables in a class. Uses Set employee.id = txtid.text Uses Get employeetemp = employee.id 21 7

Declare at module level Private mdecpay As Decimal ReadOnly Property Pay() As Decimal Get Return mdecpay End Get Read Only THERE IS NO SET Properties End Property Have No Set 22 Private mstrpassword As String Declare at the module level WriteOnly Property Password(ByVal Value as String) THERE IS NO GET Set mstrpassword = Value Write Only End Set Properties Have No End Property Get 23 Constructor A constructor is a method that automatically executes when an object is instantiated. A procedure named New 24 8

Destructor A destructor is a method that automatically executes when an object is destroyed. A procedure named Dispose overrides the Dispose method of the base class or Use the base class Dispose method 25 Overloading the Constructor Two methods have the same name but a different list of arguments A signature is the argument list of a method or procedure 26 Same name Sub New() Empty argument list End Sub Different argument lists Sub New(ByVal dhours As Decimal, ByVal drate As Decimal) Constructor that passes arguments Assign incoming values to properties mdechours = dhours mdecrate = drate End Sub Overloading the Constructor 27 9

Parameterized Constructor A constructor that requires arguments 28 Calling a Parameterized Constructor Pass it values for the parameters 29 Instantiate an object in the WebForm Class Try Dim payobject As New Payroll(Cdec(txtHours.Text),Cdec(txtRate. Text)) Catch Err As Exception MessageBox.Show( Enter the hours and rate., Payroll ) End Try 30 10

Throwing and Catching Exceptions The system throws an exception when an error occurs Your program can catch the exception and take an action OR Ignore the exception Use the Try/Catch block to enclose code that could cause an exception 31 What Exception to Throw? Use existing.net Framework exception classes Create your own exception that inherits from existing exceptions Use the System.ApplicationException class when you throw your own exceptions from application code 32 Namespaces Similar to area codes the same phone number may exist in different area codes Most classes in the.net Framework are in the System namespace Namespaces are used to organize a group of classes in the language library 33 11

Scope Determine the scope by the location of the declaration and its accessibility modifier Public or Private Scope levels Namespace Module level Procedure level Block level The area of a program that can see and reference a variable or constant. 34 Scope Namespace level Any variable, constant, class, or structure declared with the Public modifier Namespace scope means project scope 35 Scope Module level Class Level Private mdectotal As Decimal A Private variable declared inside any class, structure, or module, but outside any sub procedure or function Declare module level variables at the top of the class Use m as the scoping prefix (not standard) 36 12

Scope Procedure Level Local Scope Dim dectotal As Decimal Declare inside a procedure or function Public keyword not allowed All procedure-level variables are Private No scoping prefix in variable name 37 Scope Block Level Declared inside a code block Code blocks include: If/End If While/End While Do/Loop For/Next Select Case/End Select Try/Catch/Finally/End Try 38 Lifetime The lifetime of a variable is as long as the variable remains in scope Namespace variable lifetime as long as the program is running Module-level lifetime as long as any reference to the class remains Procedure-level one execution of the procedure 39 13

Garbage Collection The process of destroying unused objects and reclaiming memory Just allow variables to go out of scope when you are finished with them The garbage collector runs periodically and destroys objects and variables that have no active reference 40 Building Multitier Programs with Classes Advanced Programming Using Visual Basic 2008 14