Object Oriented Programming Session # 03.  Abstraction: Process of forming of general and relevant information from a complex scenarios.  Encapsulation:

Slides:



Advertisements
Similar presentations
Web Application Development Slides Credit Umair Javed LUMS.
Advertisements

Lecture 10: Part 1: OO Issues CS 540 George Mason University.
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
Written by: Dr. JJ Shepherd
Lecture 2 Basics of C#. Members of a Class A field is a variable of any type that is declared directly in a class. Fields are members of their containing.
Road Map Introduction to object oriented programming. Classes
Evan Korth New York University Computer Science I Classes and Objects 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.
Terms and Rules Professor Evan Korth New York University (All rights reserved)
Lecture 9 Concepts of Programming Languages
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
C++ fundamentals.
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
Object Oriented Software Development
A First Program Using C#
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Programming Languages and Paradigms Object-Oriented Programming.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
Overview of C# CS331. Structure of a C# Program // Specify namespaces we use classes from here using System; using System.Threading; // Specify more specific.
OOPs Object oriented programming. Based on ADT principles  Representation of type and operations in a single unit  Available for other units to create.
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.
CS200 Algorithms and Data StructuresColorado State University Part 4. Advanced Java Topics Instructor: Sangmi Pallickara
Tuc Goodwin  Object and Component-Oriented Programming  Classes in C#  Scope and Accessibility  Methods and Properties  Nested.
Learners Support Publications Classes and Objects.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
Chapter 4 Introduction to Classes, Objects, Methods and strings
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Introduction to Java Chapter 7 - Classes & Object-oriented Programming1 Chapter 7 Classes and Object-Oriented Programming.
Structures and Classes Version 1.0. Topics Structures Classes Writing Structures & Classes Member Functions Class Diagrams.
1 OOP - An Introduction ISQS 6337 John R. Durrett.
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني Introduction to Object Oriented Programming (OOP) Object Oriented programming is method of programming.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Classes, Interfaces and Packages
Object Oriented Programming. OOP  The fundamental idea behind object-oriented programming is:  The real world consists of objects. Computer programs.
1 C# - Inheritance and Polymorphism. 2 1.Inheritance 2.Implementing Inheritance in C# 3.Constructor calls in Inheritance 4.Protected Access Modifier 5.The.
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
OOP Basics Classes & Methods (c) IDMS/SQL News
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Structure A Data structure is a collection of variable which can be same or different types. You can refer to a structure as a single variable, and to.
COMPUTER SCIENCE & TECHNOLOGY DEGREE PROGRAMME FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UVA WELLASSA ‏ Properties of Object Oriented Programming.
C# Programming: From Problem Analysis to Program Design1 Creating Your Own Classes C# Programming: From Problem Analysis to Program Design 4th Edition.
Java and C# - Some Commonalities Compile into machine-independent, language- independent code which runs in a managed execution environment Garbage Collection.
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
Computer Programming II Lecture 5. Introduction to Object Oriented Programming (OOP) - There are two common programming methods : procedural programming.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
Creating Your Own Classes
Concepts of Object Oriented Programming
Programming Logic and Design Seventh Edition
3 Introduction to Classes and Objects.
Objects as a programming concept
Yanal Alahmad Java Workshop Yanal Alahmad
Module 5: Common Type System
Review: Two Programming Paradigms
Table of Contents Class Objects.
Road Map Introduction to object oriented programming. Classes
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
Lecture 9 Concepts of Programming Languages
Chapter 3 Introduction to Classes, Objects Methods and Strings
IFS410: Advanced Analysis and Design
Conditional Statements
Week 3 Object-based Programming: Classes and Objects
Classes and Objects.
COP 3330 Object-oriented Programming in C++
By Rajanikanth B OOP Concepts By Rajanikanth B
ITE “A” GROUP 2 ENCAPSULATION.
C++ Object Oriented 1.
Lecture 9 Concepts of Programming Languages
Presentation transcript:

Object Oriented Programming Session # 03

 Abstraction: Process of forming of general and relevant information from a complex scenarios.  Encapsulation: Localization of information within an object. This also leads to Information Hiding  Inheritance: Is a process by which one object acquires the properties of another object  Polymorphism: allows the programmer to use “one interface” for “many functions”. Object Oriented Concepts

Basics of C# [01]  C# code normally uses the file extension of “.cs”.  If a namespace is left out, your code is placed into the default, global, namespace.  The “using” directive tells C# what methods you would like to use from that namespace.  If we left out the “using System” statement, then we would have had to write “System.Console.WriteLine” instead of just “Console.WriteLine”.

 System.Console.WriteLine() will output a string to the console. You can use this just like Java’s System.out.println(): System.Console.WriteLine(“hello world “ + 10/2); will output: hello world 5  We can also use {0}, {1}, {2}, … etc. to indicate arguments in the WriteLine statement to print. For example: Console.WriteLine(“hi {0} you are {0} and your age is {1}”, “Kenrick”, 23); will output: hi Kenrick you are Kenrick and your age is 23 Basics of C# [02]

 There are also options to control things such as the number of columns to use for each variable, the number of decimals places to print, etc. For example, we could use :C to specify the value should be displayed as currency: Console.WriteLine(“you have {0:C} dollars.”, 1.3); outputs as: you have $1.30 dollars. Basics of C# [03]

Basics of C# [04] - Data Types  C# supports value types and reference types.  Value types are essentially the primitive types found in most languages, and are stored directly on the stack.  Reference types are objects and are created on the heap. Built-In Types Ref type

 Control Structures are statements which changes the execution sequence of the program  C++ supports all the control structures supported in C  If, else if, else  switch case  for loop  while loop  do while Control Structures

 C# extends the features of C++ Structures  C# structures can have functions as its members.  Default access specifier for Structure members is “public”. Structures in C# struct _employee { int m_iEmpId; float m_fBasic; float m_fSal; void CalculateSal() { /* Code for sal calculation */ } struct { private: /* private data member and methods */ protected: /* protected data member and methods */ public: /* public data member and methods */ };

 ‰ Are the heart of object oriented programming.  It is a collection of objects.  A class is simply a representation of a type of object.  ‰ Application structure mirrors real world objects  ‰ Related methods and data encapsulated in object  ‰ Objects with the same structure are of same type  ‰ A class is a blueprint for all things of that type  ‰ Instance (request) of a class is a thing, an object  ‰ Classes have three main types of members:  ‰ Methods (functions in other languages)  ‰ Fields (the data, sometimes called member variables)  ‰ Properties (accessed like fields, but actually methods) Class [01]

 Basic unit of abstraction in C#  Extension of the concept of structures  Provides a technique way to bind data and functions together (Encapsulation)  Data Members – Variables declared inside the class  Member Functions – Functions declared/defined inside the class  Member Functions are also called as Methods Class [02] class { private: /* private data member and methods */ protected: /* protected data member and methods */ public: /* public data member and methods */ }; class Employee { int m_iEmpId; float m_fBasic; public: void CalculateSal() { /* Code for sal calculation */ }

Declaration of class and object

 An object is basically a block of memory that has been allocated and configured according to the class.  A program may create many objects of the same class.  Objects are also called instances of a class.  Instance of a class in memory  Unique, identifiable, self – contained entity that contains attributes and behaviors  If class is viewed as a data type then object can be considered as a variable of class data type. Objects

Objects-Example [01]

 In the above C# code, we have a Person class with one member field.  We declare a name member field. The public keyword specifies that the member field will be accessible outside the class block.  We use the dot operator to access the attributes of objects. Objects-Example [02]