OOP in C# - part 1 OOP in C#: –Object Interaction. –Inheritance and Polymorphism (next module). FEN 20121UCN Technology: Computer Science.

Slides:



Advertisements
Similar presentations
Written by: Dr. JJ Shepherd
Advertisements

IMPLEMENTING CLASSES Chapter 3. Black Box  Something that magically does its thing!  You know what it does but not how.  You really don’t care how.
1 l Inheritance Basics l Programming with Inheritance l Dynamic Binding and Polymorphism Inheritance.
1 OOP in C#:Object Interaction. Inheritance and Polymorphism. Session 2: OOP in C#
Introduction to Object-Oriented Programming CS 21a: Introduction to Computing I First Semester,
Chapter 3 Implementing Classes. Instance Variables Instance variables store the data of an object; the fields of an object. Instance of a class: an object.
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. Chapter Three - Implementing Classes.
Session 07: C# OOP 4 Review of: Inheritance and Polymorphism. Static and dynamic type of an object. Abstract Classes. Interfaces. FEN AK - IT:
Classes. Object-Oriented Design Method for designing computer programs Consider “objects” interacting in the program –Example: a zoo, a gradebook.
Road Map Introduction to object oriented programming. Classes
Classes. Object-Oriented Design Method for designing computer programs Consider “objects” interacting in the program –Example: a zoo, a gradebook.
Object Oriented Programming.  OOP Basic Principles  C++ Classes  September 2004  John Edgar 22.
Chapter 3 Implementing Classes. Chapter Goals To become familiar with the process of implementing classes To be able to implement simple methods To understand.
Lecture 9 Concepts of Programming Languages
Abstract Data Types and Encapsulation Concepts
Object Oriented Software Development
Programming Languages and Paradigms Object-Oriented Programming.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Writing Classes (Chapter 4)
CSM-Java Programming-I Spring,2005 Objects and Classes Overview Lesson - 1.
Module 7: Object-Oriented Programming in Visual Basic .NET
Introduction to Object-Oriented Programming
1 OOP in C#: Object Interaction. Inheritance and Polymorphism OOP in C# - Del 1.
Week 4 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
Object-Oriented Programming in C++
Classes CS 21a: Introduction to Computing I First Semester,
Chapter 7 Objects and Classes 1 Fall 2012 CS2302: Programming Principles.
ACO 101: Introduction to Computer Science Anatomy Part 2: Methods.
Java Objects and Classes. Overview n Creating objects that belong to the classes in the standard Java library n Creating your own classes.
P Chapter 2 introduces Object Oriented Programming. p OOP is a relatively new approach to programming which supports the creation of new data types and.
Week 4 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Session 2: OOP in C# OOP in C#: –Object Interaction. –Inheritance and Polymorphism. Autumn 20121UCN Technology: IT/Computer Science.
1 Announcements Note from admins: Edit.cshrc.solaris instead of.tcshrc Note from admins: Do not use delta.ece.
Session 04: C# OOP 2 OOP in C#: Object-Oriented Design.
Session 02 and 03: C# OOP 1 OOP in C#: Classes and Objects in C#. Object-Oriented Design. UML Class Diagram. Object Interaction. FEN AK IT:
Overview The Basics – Python classes and objects Procedural vs OO Programming Entity modelling Operations / methods Program flow OOP Concepts and user-defined.
CS451 - Lecture 2 1 CS451 Lecture 2: Introduction to Object Orientation Yugi Lee STB #555 (816) * Acknowledgement:
Classes. Constructor A constructor is a special method whose purpose is to construct and initialize objects. Constructor name must be the same as the.
Object-Oriented Programming (OOP) What we did was: (Procedural Programming) a logical procedure that takes input data, processes it, and produces output.
FEN 2014UCN Teknologi/act2learn1 Object-Oriented Programming “ The Three Pillars of OOP”: Encapsulation Inheritance Polymorphism The Substitution Principle.
Object Oriented Programming. OOP  The fundamental idea behind object-oriented programming is:  The real world consists of objects. Computer programs.
Chapter 7 Classes and Methods III: Static Methods and Variables Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition)
YG - CS Concept of Encapsulation What is encapsulation? - data and functions/methods are packaged together in the class normally.
Classes CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
Topics Instance variables, set and get methods Encapsulation
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. Chapter Three - Implementing Classes.
Chapter 3 Implementing Classes
COMPUTER SCIENCE & TECHNOLOGY DEGREE PROGRAMME FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UVA WELLASSA ‏ Properties of Object Oriented Programming.
Computer Programming II Lecture 5. Introduction to Object Oriented Programming (OOP) - There are two common programming methods : procedural programming.
Classes (Part 1) Lecture 3
Classes C++ representation of an object
Java OOP Overview Classes and Objects, Members and Class Definition, Access Modifier, Encapsulation Java OOP Overview SoftUni Team Technical Trainers.
Classes and OOP.
Lecture 9 Concepts of Programming Languages
Chapter Three - Implementing Classes
What is an object? An object represents an individual, identifiable item, unit, or entity, either real or abstract, with a well-defined role in the.
Inheritance Basics Programming with Inheritance
Dr. Bhargavi Dept of CS CHRIST
Computer Programming with JAVA
CS2011 Introduction to Programming I Objects and Classes
JAVA CLASSES.
Classes CS 21a: Introduction to Computing I
Introduction to Object-Oriented Programming
Classes C++ representation of an object
Classes.
Lecture 9 Concepts of Programming Languages
Introduction to Computer Science and Object-Oriented Programming
Presentation transcript:

OOP in C# - part 1 OOP in C#: –Object Interaction. –Inheritance and Polymorphism (next module). FEN 20121UCN Technology: Computer Science

FEN 2012UCN Technology: Computer Science2 Object-Oriented Programming “ The Three Pillars of OOP”: Encapsulation Inheritance Polymorphism The Substitution Principle

FEN 2012UCN Technology: Computer Science3 OO-Principles -encapsulation Seen from the outside an object is an entity offering a number of services (public methods and properties). The implementation and data representation are hidden or encapsulated. –This makes it possible to change implementation without affecting other parts of the program. –Also it becomes possible to think, talk and use the object without knowing the implementation. –Hiding data behind methods and properties are called encapsulation or data abstraction. Encapsulation or data abstraction is one the fundamental principles of object-oriented programming.

FEN 2012UCN Technology: Computer Science4 Definition of Object and Class Object –Represents a real-world concept, realised by data (attributtes) associated with the concept and a number of operations (methods)that may be used to access the attributes of the object. Class –A type that defines the attributes and methods of a set of objects that all represent instances of the same real-world concept. The class describes the structure of the concept, and the objects are the actual instances of the class. The class is static – exists only compile time. Objects are dynamic – exist runtime.

FEN 2012UCN Technology: Computer Science5 Attributes (data) Attributes define the data to be stored (name and type). Attributes are defined in the class, and are assign values in the objects. E.g.: –Account: accountNo, balance, maxLimit, interestRate etc. –Employee: name, departmentNo, salery, jobTitle etc. The state of an object is given by the value of its attributes at a given time.

FEN 2012UCN Technology: Computer Science6 Methods (operations) The operations of an object are defined by the methods implemented in the class. Calls to methods either return information about the state of the object (accessors) or change the state of the object (mutators). BankAccount –WithDraw(), Deposite(), GetBalance() etc. Employee –GiveASaleryRaise (), SetTitle() etc.

FEN 2012UCN Technology: Computer Science7 Properties (C# speciality) Are used for getting and setting attribute values. (Replace set- and get-methods in Java). Provide a syntax similiar to direct access of the attributes. (Anders Hejsberg footprint?)

FEN 2012UCN Technology: Computer Science8 Constructor Method(s) with the same name as the class and no return type.The job of a constructor is to initialise the attributes of the object during object creation. E.g. Creating an object –Account acc = new Account(); Account() is a call to the constructor. The new command –Allocates memory for the object. –Assigns the variable (the reference) acc to the allocated block of memory – new is actually a function that returns an address in the heap. Constructors may be overloaded

FEN 2012UCN Technology: Computer Science9 The Anatomy of a Class Classes are usually written by this pattern: class ClassName { declaration of attributes constructors properties methods }

FEN 2012UCN Technology: Computer Science10 Methods Metodenavn (parameter list) { statements } public int SumOf2Ints (int int1, int int2) { int sum; sum = int1 + int2; return sum; } Acessmodifier: public/protected /private Local variable return Parameters

FEN 2012UCN Technology: Computer Science11 The Class Account - attributes and constructor namespace Banking { public class Account { private double balance; private int accNo; private int interestRate; public Account(int no, int ir) { balance = 0; accNo = no; intrestRate = ir; }

FEN 2012UCN Technology: Computer Science12 Methods public bool Withdraw(double amount) public void Deposite(double amout) public void GiveInterest()

FEN 2012UCN Technology: Computer Science13 Properties public int InterestRate { get{return interestRate;} set{if( value>=0) interestRate = value;} } Lets do in C# using Visual Studio. Source here.here

FEN 2012UCN Technology: Computer Science14 Exercise Create a VS project using this code: EmpProjectV1.rar EmpProjectV1.rar Test it – understand it. Banking exercise.Banking exercise