Classes & Objects A deeper Look Chapter 10 & 11

Slides:



Advertisements
Similar presentations
CSCI 3328 Object Oriented Programming in C# Chapter 9: Classes and Objects: A Deeper Look 1 Xiang Lian The University of Texas – Pan American Edinburg,
Advertisements

OOP: Inheritance By: Lamiaa Said.
CSE 1302 Lecture 8 Inheritance Richard Gesick Figures from Deitel, “Visual C#”, Pearson.
Inheritance Inheritance Reserved word protected Reserved word super
Object-Oriented Programming: Inheritance Deitel &Deitel Java SE 8.
More about classes and objects Classes in Visual Basic.NET.
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 8.1 – 8.5.
Summary of text to be covered Create your own class Create and use objects of your own class Control access to object instance variables Use keyword private.
Advanced Object-Oriented Programming Features
1 Evan Korth New York University Inheritance and Polymorphism Professor Evan Korth New York University.
C++ Classes in Depth. Topics Designing Your Own Classes Attributes and Behaviors Writing Classes in C++ Creating and Using Objects.
1 Evan Korth New York University Inheritance and Polymorphism Professor Evan Korth New York University.
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.
Computer Science I Inheritance Professor Evan Korth New York University.
Object-Oriented Programming: Inheritance Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
Object-Oriented Programming: Inheritance
Object Based Programming. Summary Slide  Instantiating An Object  Encapsulation  Inheritance  Polymorphism –Overriding Methods –Overloading vs. Overriding.
CS0004: Introduction to Programming Variables – Numbers.
Lecture 8 Inheritance Richard Gesick. 2 OBJECTIVES How inheritance promotes software reusability. The concepts of base classes and derived classes. To.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Object Oriented Concepts
Lecture 9 Polymorphism Richard Gesick.
Module 7: Object-Oriented Programming in Visual Basic .NET
Programming Pillars Introduction to Object- Oriented Programming.
CSCI 3327 Visual Basic Chapter 3: Classes and Objects UTPA – Fall 2011.
Visual C# 2012 for Programmers © by Pearson Education, Inc. All Rights Reserved.
CSCI 3327 Visual Basic Chapter 9: Object-Oriented Programming: Classes and Objects UTPA – Fall 2011.
8. Inheritance “Is-a” Relationship. Topics Creating Subclasses Overriding Methods Class Hierarchies Abstract Class Inheritance and GUIs The Timer Class.
VB Classes ISYS 512/812. Object-Oriented Concepts Abstraction: –To create a model of an object, for the purpose of determining the characteristics (properties)
Inheritance Objectives: Creating new classes from existing classes The protected modifier Creating class hierarchies Abstract classes Indirect visibility.
Object Oriented Programming
CIS 270—Application Development II Chapter 8—Classes and Objects: A Deeper Look.
EGR 2261 Unit 11 Classes and Data Abstraction  Read Malik, Chapter 10.  Homework #11 and Lab #11 due next week.  Quiz next week.
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 9.1 – 9.4.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Chapter 2 11/18/2015 © by Pearson Education, Inc. All Rights Reserved. Lect9 GC 2011.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Object-Oriented Programming: Classes and Objects Chapter 1 1.
Object-Oriented Programming: Classes and Objects.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
These materials where developed by Martin Schray
CompSci 230 S Programming Techniques
Classes and Objects: A Deeper Look
Object-Oriented Programming: Classes and Objects
Java Programming: Guided Learning with Early Objects
Week 4 Object-Oriented Programming (1): Inheritance
Road Map Inheritance Class hierarchy Overriding methods Constructors
Object-Oriented Programming: Classes and Objects
Object-Oriented Programming: Inheritance
Lecture 23 Polymorphism Richard Gesick.
The University of Texas Rio Grande Valley
Object-Oriented Programming: Inheritance
Introduction to Classes
MSIS 670 Object-Oriented Software Engineering
Lecture 22 Inheritance Richard Gesick.
Inheritance, Polymorphism, and Interfaces. Oh My
IS437: Fall 2004 Instructor: Dr. Boris Jukic
CSCI 3328 Object Oriented Programming in C# Chapter 9: Classes and Objects: A Deeper Look – Exercises UTPA – Fall 2012 This set of slides is revised from.
Advanced Programming Behnam Hatami Fall 2017.
CSCI 3327 Visual Basic Chapter 6: Methods: A Deeper Look
Object-Oriented Programming: Inheritance
Object-Oriented Programming: Classes and Objects
Tonga Institute of Higher Education
CSCI 3328 Object Oriented Programming in C# Chapter 9: Classes and Objects: A Deeper Look UTPA – Fall 2012 This set of slides is revised from lecture.
Object-Oriented Programming: Inheritance
Fundaments of Game Design
Object-Oriented Programming: Inheritance
Presentation transcript:

Classes & Objects A deeper Look Chapter 10 & 11 Dr. John P. Abraham Professor UTPA

UML Class Diagram Unified Modeling Language A graphical language that allows people to use industry standard notations. See an example of UML class dagram on page 131, 136,143 of your textbook.

Initializing objects with constructors The constructor class is called by the class name followed by parenthesis. Constructor subroutine can be declared with the ‘new’ key word. Public sub New(ByVal name as string)

Constructors If programmer did not write a constructor, the compiler provides a default parameterless constructor. You can also write a parameterless constructor Overloaded constructors You can provide multiple constructors.

Overloaded constructor example Public Sub New() setTime(12) ‘initialize to noon End sub Public Sub New(byVal hh as integer) setTime(hh) ‘initialize the hour to whatever Public sub new (byval hh as integer, byval mm as integer) setTime(hh,mm) End Sub

Modules, Classes and Methods Both classes and Modules contain methods (subs). Related classes are grouped into namespaces and compiled into library files. A module contains declarations and procedures that are used by other files in a project. Module is not associated with a class or form and contain no event procedures. Good to use in case you are using multiple forms.

Partial classes Vb allows a class declaration to span multiple source-code files. This allows programming teams to work on a single class! If a class is stored in different files, each file is a partial class.

Composition When a class reference objects of other classes as members of self. Sometimes referred to has has-a relationship. Example A class employee may use an object of day for birthday or hireDate.

Shared Class Members Each time an object is created, it gets a portion of the memory. Multiple variables of the same class will have multiple memory portions. Assigning just one portion of memory and sharing it by many objects allows class-wide sharing of information. Declare such members with keyword shared. Shared members can be accessed through the class members name using the dot separator.

Const and Read only Members Const: Once a value is given it can’t be changed. Const must be given a value at declaration Read only can be assigned a value at declaration or at constructor execution. It can only assigned a value once (can’t be changed)

Delegates A delegate is an object that holds a reference to a method. Delegates allow you to treat methods as data. Meaning you can assign methods to variables and pass methods to and from methods.

Protected members A base class’s private members are not inherited by derived classes. Protected access offers an intermediate level of access between Public and Private. A base class’s protected members can be accessed only by members of that base class and by members of its derived classes.

Friend Members Friend access is another intermediate level access. If a program uses multiple classes from the same assembly, these classes can access each other’s friend members. Unlike public access, programs that are declared outside the assembly cannot access these Friend Members.

Inheritance New class is created from an existing one by adding new or modified capabilities. The new class is a derived class or subclass. A derived class can become a base class for a future derived class. Is-a relationship –represents inheritance (a car is a vehicle) Has-a relationship represents a composition. A car has a steering wheel.

Base and derived classes A rectangle, square, parallelogram, and a trapezoid is a quadrilateral. Thus a (derived) class Rectangle can be said to inherit from (base) class Quadrilateral. An inheritance hierarchy can be drawn to show relationships.

Extension Methods You can’t modify code for classes you did not create. In VB 2008 you can use extension methods to add functionality to an existing class without modifying the class’s source code.

Time Class Private hourValue As Integer ' 0 - 23 Private minuteValue As Integer ' 0 - 59 Private secondValue As Integer ' 0 – 59 Public Sub New() SetTime(12, 0, 0) ' initialize hour to noon; minute, second to 0 End Sub

Set & Get Time Public Sub SetTime(ByVal hh As Integer, _ ByVal mm As Integer, ByVal ss As Integer) Hour = hh Minute = mm Second = ss End Sub ' SetTime Public Property Hour() As Integer Get Return hourValue End Get Public Property Minute() As Integer Return minuteValue --do the same for second-

24 hour clock Public Function ToUniversalString() As String Return String.Format("{0}:{1:D2}:{2:D2}", Hour, Minute, Second) End Function

Standard 12 hour time Public Overrides Function ToString() As String Dim suffix As String ' AM or PM suffix Dim standardHour As Integer If Hour < 12 Then suffix = "AM" Else suffix = "PM" End If If (Hour = 12 OrElse Hour = 0) Then standardHour = 12 standardHour = Hour Mod 12 End If Return String.Format("{0}:{1:D2}:{2:D2} {3}", _ standardHour, Minute, Second, suffix) End Function