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

Lecture 18 Tao Wang 1

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

Chapter 10 Introduction to Classes

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

Computer Programming with C++ (21)

Advanced Programming Using Visual Basic 2008

CIS Intro to Programming in C#

Object Oriented Design

Introduction to Programming session 24

Microsoft Visual Basic 2005: Reloaded

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

Object Oriented Programming in C#

Classes: A Deeper Look

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

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

Inheritance and Polymorphism

Chapter 4 Defining Classes I

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

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


Object Oriented Programming

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.

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

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

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

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

Programming I. Course 9 Introduction to programming

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

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

Software Development With Java CSCI

Lecture 5. Function Pointers

Fundamental Concepts and Definitions

CLASSES AND OBJECTS IN JAVA

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

Introduction to Classes

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

Introduction to Programming Using Java (98-388)

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

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

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

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS313D: ADVANCED PROGRAMMING LANGUAGE

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

OBJECT-ORIENTED PROGRAMMING CONCEPTS-CLASSES IV

Java Primer 1: Types, Classes and Operators

7. C++ Class and Object

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.

Object-Oriented Programming

CMSC 132: Object-Oriented Programming II

CS111: PROGRAMMING LANGUAGE II

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

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

Abstraction in Software Development

Cpt S 122 Data Structures. Introduction to C++ Part II

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

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

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

Java Object Oriented Design. CSC207 Fall 2014

Object Oriented Design

EEE-425 Programming Languages (2013) 1

Object oriented programming. Encapsulation. Polymorphism. Inheritance OOP

Object Orientated Analysis and Design. Benjamin Kenwright

Chapter 9 Classes : A Deeper Look, Part 1

JAVA GUI PROGRAMMING REVISION TOUR III

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

CS1004: Intro to CS in Java, Spring 2005

KOM3191 Object Oriented Programming Dr Muharrem Mercimek OPERATOR OVERLOADING. KOM3191 Object-Oriented Programming

CS360 Lecture 5 Object-Oriented Concepts

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

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

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

Classes and Objects: A Deeper Look

Tentative Teaching Plan Department of Software Engineering Name of Teacher Dr. Naeem Ahmed Mahoto Course Name Computer Programming

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

CSC 330 Object-Oriented Programming. Encapsulation

Chapter 6 Introduction to Defining Classes

Introduction To C#.NET

BBM 102 Introduction to Programming II Spring Inheritance

Inheritance. Lecture 11 COP 3252 Summer May 25, 2017

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

Anatomy of a Class Encapsulation Anatomy of a Method

Public Class ClassName (naming: CPoint)

EEE-425 Programming Languages (2013) 1

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

OBJECT-ORIENTED PROGRAMMING CONCEPTS-CLASSES II

CMSC 132: Object-Oriented Programming II

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

CS260 Intro to Java & Android 03.Java Language Basics

MaanavaN.Com CS1203 OBJECT ORIENTED PROGRAMMING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

Object-Oriented Design (OOD) and C++

Object-Oriented Programming

Transcription:

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

Lecture Contents What is a class? Class definition: Data Methods Constructors Properties (set/get) objects Object initializers Static members Readonly members Composition

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

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

Initializing data with Constructors 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.

Overloaded Constructors 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 Class Time2 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 Private data Overloaded constructors Constructor initializers Using this operator

The Time2 Class get/set provide controlled ways to get (i.e., retrieve) the value in an instance variable and set (i.e., modify) the value in an instance variable.

The Time2 Class get/set By convention, we name each property with the capitalized name of the instance variable that it manipulates

The Time2 Class datavalidation Convert to string representation

The Time2 Class Convert to string representation

Test!!

Test

Test

Object Initializers allow you to create an object and initialize its public properties (and public instance variables, if any) in the same statement. Can be useful when a class does not provide an appropriate constructor, but does provide properties on the class s data.

The destructor 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 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

readonly Instance Variables 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.

readonly Instance Variables 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 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.

Case study Read-only fields

That s all for today Chapter 4 Chapter 10

29 Self Reading Dr. MH, Autumn17

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

Self Reading Blueprint of a house Design build use Attributes?? Methods??

Self Reading the Unified Modeling Language (UML) 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.

Self Reading Example Mark Visibility type + Public # Protected - Private

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

Self Reading Be careful!!

Self Reading How to define a Class?? Class type definition Object declaration Methods call

Self Reading Tip!!