CS313D: ADVANCED PROGRAMMING LANGUAGE

Similar documents
CS313D: ADVANCED PROGRAMMING LANGUAGE

Lecture Contents CS313D: ADVANCED PROGRAMMING LANGUAGE

CS313D: ADVANCED PROGRAMMING LANGUAGE

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

Constructors for classes

Advanced Programming Using Visual Basic 2008

Lecture 18 Tao Wang 1

And Even More and More C++ Fundamentals of Computer Science

Computer Programming with C++ (21)


Chapter 9 Objects and Classes. Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved.

Introduction to Programming session 24

Object Oriented Programming in C#

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

Chapter 4 Defining Classes I

Object Oriented Design

Chapter 10 Introduction to Classes

CMPT 117: Tutorial 1. Craig Thompson. 12 January 2009

Computer Science II. OO Programming Classes Scott C Johnson Rochester Institute of Technology

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

C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 12: Classes and Data Abstraction

C++ (Non for C Programmer) (BT307) 40 Hours

Object Oriented Programming

Classes: A Deeper Look

Introduction to Classes

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

Object-Oriented Programming

7. C++ Class and Object

CIS Intro to Programming in C#

15CS45 : OBJECT ORIENTED CONCEPTS

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

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

Object oriented programming. Encapsulation. Polymorphism. Inheritance OOP

Software Development With Java CSCI

by Pearson Education, Inc. All Rights Reserved. 2

Lecture 5. Function Pointers

Unit3: Java in the large. Prepared by: Dr. Abdallah Mohamed, AOU-KW

Fundamental Concepts and Definitions

Inheritance and Polymorphism

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

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

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #1 Examination 12:30 noon, Tuesday, February 14, 2012

Microsoft Visual Basic 2005: Reloaded

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

JAVA GUI PROGRAMMING REVISION TOUR III

C++ Inheritance and Encapsulation

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Object Oriented Features. Inheritance. Inheritance. CS257 Computer Science I Kevin Sahr, PhD. Lecture 10: Inheritance

Classes and Objects: A Deeper Look

CS313D: ADVANCED PROGRAMMING LANGUAGE

l A class in C++ is similar to a structure. - It allows you to define a new (composite) data type. l A class contains the following: - variables AND

! Data is stored in variables. - Perhaps using arrays and structs. ! Program is a collection of functions that perform

EEE-425 Programming Languages (2013) 1

Objects and Classes. Amirishetty Anjan Kumar. November 27, Computer Science and Engineering Indian Institue of Technology Bombay

EEE-425 Programming Languages (2013) 1

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

Data Structures using OOP C++ Lecture 3

CS304 Object Oriented Programming Final Term

Introduction to Visual Basic and Visual C++ Introduction to Java. JDK Editions. Overview. Lesson 13. Overview

CS313D: ADVANCED PROGRAMMING LANGUAGE. Lecture 3: C# language basics II

Programming I. Course 9 Introduction to programming

Java Primer 1: Types, Classes and Operators

CS111: PROGRAMMING LANGUAGE II

12/22/11. Java How to Program, 9/e. public must be stored in a file that has the same name as the class and ends with the.java file-name extension.

Lecture #1. Introduction to Classes and Objects

! Data is stored in variables. - Perhaps using arrays and structs. ! Program is a collection of functions that perform

CMSC 132: Object-Oriented Programming II

2/3/2018 CS313D: ADVANCED PROGRAMMING LANGUAGE. Lecture 3: C# language basics II. Lecture Contents. C# basics. Methods Arrays. Dr. Amal Khalifa, Spr17

Topics. Topics (Continued) 7.1 Abstract Data Types. Abstraction and Data Types. 7.2 Object-Oriented Programming

Inheritance. Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L

C++ Inheritance and Encapsulation

Subclass Gist Example: Chess Super Keyword Shadowing Overriding Why? L10 - Polymorphism and Abstract Classes The Four Principles of Object Oriented

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

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

Object Oriented Programming. Solved MCQs - Part 2

Abstraction in Software Development

CLASSES AND OBJECTS IN JAVA

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

l A class in C++ is similar to a structure. - It allows you to define a new (composite) data type. l A class contains the following: - variables AND

Object Orientated Analysis and Design. Benjamin Kenwright

Java Object Oriented Design. CSC207 Fall 2014

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

QUIZ on Ch.5. Why is it sometimes not a good idea to place the private part of the interface in a header file?

! Data is stored in variables. - Perhaps using arrays and structs. ! Program is a collection of functions that perform

Chapter 13: Introduction to Classes Procedural and Object-Oriented Programming

A A B U n i v e r s i t y

Encapsulation in C++

ECOM 2324 COMPUTER PROGRAMMING II

CS360 Lecture 5 Object-Oriented Concepts

OBJECT-ORIENTED PROGRAMMING CONCEPTS-CLASSES IV

BBM 102 Introduction to Programming II Spring Inheritance

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

Introduction To C#.NET

Programming for Engineers in Python

! Data is stored in variables. - Perhaps using arrays and structs. ! Program is a collection of functions that perform

CS313D: ADVANCED PROGRAMMING LANGUAGE

Object Class. EX: LightSwitch Class. Basic Class Concepts: Parts. CS257 Computer Science II Kevin Sahr, PhD. Lecture 5: Writing Object Classes

Chapter 6 Introduction to Defining Classes

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

1. Describe History of C++? 2. What is Dev. C++? 3. Why Use Dev. C++ instead of C++ DOS IDE?

Transcription:

CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 4 (a): Classes & Objects

Lecture Contents 2 What is a class? Class definition: Data Methods Constructors objects Static members Readonly members composition

What is a class? 3 Class: like a struct in C++, defines a data type (blueprint) Combines data and operations in one place: data / fields/ properties / state variables Operations/ behavior / methods that modify state

4 Encapsulation The bundling of data and procedures(methods) into a single unit(called class). Class : various data elements and member functions are wrapped up together. main feature of object oriented programming

Objects & Classes 5 variables of class type are objects Object: an instance / realization of a class same as relationship between a datatype and its variables

6 Blueprint of a house Design build use Attributes?? Methods??

How to define a Class?? 7 Type definition Object declaration Member access

the Unified Modeling Language (UML) 8 can be defined as a modeling language to capture the architectural, behavioral and structural aspects of a system. The UML has an important role in object oriented analysis and design. Objects are the key to this object oriented world The basic requirement of is to identify the object efficiently.

9 Examples What about a student??

10 Access modifiers Public items (usually member functions) are "user-accessible Outside of class definition, cannot change (or even access) private data

Mark Visibility type + Public # Protected - Private ~ Package 11 Marks for UML-supported visibility types

Initializing data with Constructors 12 A constructor can be used to initialize an object of a class when the object is created. Every class must have at least one constructor. If you do not provide any constructors in a class s declaration the compiler creates a default constructor that takes no arguments when it is invoked. if you declare any constructors no default constructor will be created for that class With the default constructor, its instance variables are initialized to their default values.

13 Be careful!!

Overloaded Constructors 14 Overloaded constructors enable objects of a class to be initialized in different ways. multiple constructor declarations with different signatures. the compiler differentiates signatures by : the number of parameters, the types of the parameters and the order of the parameter types in each signature.

Time Class Case Study 15 Class Time1 represents the time of day in universal-time format (24-hour clock format). instance variables hour, minute and second methods: Property set/get five overloaded Constructors settime ToUniversalString ( hh:mm:ss) ToString (hh:mm:ss AM/PM)

The Time2 Class 16 Private data Overloaded constructors Constructor initializers Using this operator

The Time2 Class 17 get/set

The Time2 Class 18 get/set

The Time2 Class 19 Convert to string representation

The Time2 Class 20 Convert to string representation

Test!! 21

Test 22

Test 23

24

25

The destructor 26 Object destructor: Same as the class name, preceded by a tilde, with no access modifier in its header. called by the Common Language Runtime (CLR) garbage collector to perform termination housekeeping on an before its memory is reclaimed. not guaranteed to execute at a specified time. Rarely used

static Class Members 27 static field: called a class variable represents class-wide information only one copy is be shared by all objects of a class. The declaration begins with the keyword static. public static members can be accessed through a reference to any object of the class, or by qualifying the member name with the class name and a dot (.). A class s private static class members can be accessed only through the methods and properties of the class. To access a private static member from outside its class, a public static method or property can be provided

28 Tip!!

readonly Instance Variables 29 C# provides keyword readonly to specify that an instance variable of an object is not modifiable and that any attempt to modify it after the object is constructed is an error. Like constants, readonly variables are declared with all capital letters by convention readonly instance variables can be initialized when they are declared, but this is not required. Members that are declared as const must be assigned values at compile time, whereas members declared with keyword readonly, can be initialized at execution time. If a class provides multiple constructors, every constructor should initialize a readonly variable.

Composition 30 A class can have references to objects of other classes as members. This is called composition and is sometimes referred to as a has-a relationship. Examples: An AlarmClock object needs two references to Time objects to know the current time and the time when it s supposed to sound its alarm. A Robot Object has-a MechanicalArm A car Object has-a Wheel A student Object has-a BirthDate You name it!!!

31 That s all for today Chapter 10