• No results found

Programming 2 (CS-2300)

N/A
N/A
Protected

Academic year: 2020

Share "Programming 2 (CS-2300)"

Copied!
48
0
0

Loading.... (view fulltext now)

Full text

(1)

Programming 2 (CS-2300)

(2)

Different Programming Paradigms

⚫ Functional/procedural programming:

⚫ program is a list of instructions to the computer

⚫ Object-oriented programming

program is composed of a collection objects that

(3)

3

History of Object-Oriented Programming

⚫ Started out for simulation of complex man-machine

systems, but was soon realized that it was suitable for all complex programming projects

⚫ SIMULA I (1962-65) and Simula 67 (1967) were the first two object-oriented languages

⚫ Developed at the Norwegian Computing Center, Oslo, Norway by Ole-Johan Dahl and Kristen Nygaard

⚫ Simula 67 introduced most of the key concepts of

object-oriented programming: objects and classes, subclasses (“inheritance”), virtual procedures

(4)

4

The Ideas Spread

⚫ Alan Kay, Adele Goldberg and colleagues at Xerox PARC extend the ideas of Simula in developing Smalltalk

(1970’s)

⚫ Kay coins the term “object oriented”

⚫ Smalltalk is first fully object oriented language

⚫ Grasps that this is a new programming paradigm

⚫ Integration of graphical user interfaces and interactive program execution

⚫ Bjarne Stroustrup develops C++ (1980’s)

⚫ Brings object oriented concepts into the C programming language

(5)

5

Other Object Oriented Languages

⚫ Eiffel (B. Meyer)

⚫ CLOS (D. Bobrow, G. Kiczales)

⚫ SELF (D. Ungar et al.)

⚫ Java (J. Gosling et al.)

⚫ BETA (B. Bruun-Kristensen, O. Lehrmann Madsen, B. Møller-Pedersen, K. Nygaard)

⚫ Other languages add object dialects, such as TurboPascal

(6)

What is procedural Approach ?

⚫ In Procedural approach - code is organised(ﺔﻤﻈﻨﻤﻟا) into small "procedures (تاءاﺮﺟﻹا) that use and change the data.

⚫ Functions(تاءاﺮﺟﻹا) take some input.

⚫ Function Processes the input.

⚫ Function produce some output.

Shared Data

Function_1 Function_2 Function - 3

Output Output

(7)

Object Oriented Programming ?

⚫ Data and Functions are grouped (ﻊﯿﻤﺠﺗ )together into class (ﺔﺌﻓ).

⚫ Class instantiates or creates (ﻖﻠﺧ)objects (مﺎﺴﺟﻷا).

⚫ the data inside an object can only be manipulated (ﺐﻋﻼﺘﻟا ) by calling the object's functions.

⚫ Data is locked( ﻞﻔﻘﻣ) inside object .

(8)

Function 1

Function 2

Private Data

(9)

Mapping the world to software

Objects in the problem domain are mapped to

objects in software

011101 10011 11101 0110100 11010 010101 1110101 10101

(10)

⚫ Procedural Programming

⚫ Program is based(ﺪﻨﺘﺴﺗ) on

functions.

⚫ Importance (ﺔﯿﻤھأ) is not given to data but

Functions.

Top Down approach.

⚫ To add new data and

function in POP is not so easy.

⚫ No data hiding( ءﺎﻔﺧإ) – less secure. ⚫ Eg : C, VB, FORTRAN, Pascal. ⚫ Object Oriented Programming ⚫ program is based on objects. ⚫ Importance is given to

data not functions.

Bottom up approach.

⚫ An easy way to add new data and function.

⚫ Data is hidden – More security(ﻦﻣأ)

⚫ Example of OOP : C++, JAVA, VB.NET, C#.NET.

(11)

Problem Description

⚫ “ …customers are allowed to have different types of bank accounts, deposit money, withdraw money and transfer

(12)

Procedural Approach cont’d

⚫ Focus is on procedures

⚫ All data is shared: no protection

⚫ More difficult to modify

(13)

Procedural Approach

bool MakeDeposit(int accountNum,float amount); float Withdraw(int accountNum,float amount);

struct Account { char *name; int accountNum; float balance; char accountType; };

(14)

Procedural vs. Object-Oriented

⚫ Procedural

Withdraw, deposit, transfer

⚫ Object Oriented

(15)

Object Oriented

Data and operations are grouped together

Account

Withdraw Deposit Transfer

Interface:

(16)

Main OOPs Concepts

⚫ Object ⚫ Class ⚫ Encapsulation ⚫ Inheritance ⚫ Polymorphism

(17)

Objects and Classes

Classes reflect concepts, objects reflect instances

that embody those concepts.

Daria Jane Brittany Jodie

girl

class

(18)

Objects and Classes cont’d

A class captures(ﻂﻘﺘﻠﯾ) the common properties

(ﺔﻛﺮﺘﺸﻣ ﺺﺋﺎﺼﺧ) of the objects instantiated from it.

⚫ A class characterizes the common behavior (كﻮﻠﺴﻟا ﺔﻛﺮﺘﺸﻤﻟا) of all the objects that are its instances.

(19)

Objects and Classes cont’d

Class BankAccount Balance InterestYTD Owner Account_number Balance 500 InterestYTD = 40 Owner = Sarah Ali Account_number = “1000101676” Balance 10,000 InterestYTD = 300 Owner = “Haya Dosairi” Account_number = “1000546564” Operations MakeDesposit Transfer WithDraw GetBalance

(20)

Objects

⚫ Object are Instances of classes

⚫ It has

-identity – unique identification of an object -attributes – data/state

-services – methods/operations supported by the object

(21)

Class : BOX (Identity) Int Length; Int Breadth; Int Height; Find_Area() Display_Area() Object : B1 Length = 5; Breadth = 4; Height =3; Object B2 Length = 7; Breadth = 6; Height =2; Attributes Methods Find_Area()

(22)

Class

⚫ Class define the nature and properties (ﺺﺋﺎﺼﺧ) of objects

object is an instance of class

⚫ class groups similar objects

⚫ same (structure of) attributes

⚫ same services

(23)

Objects as instances of Classes

The world conceptually(ﺔﯿﻤﯿھﺎﻔﻤﻟا ﺔﯿﺣﺎﻨﻟا ﻦﻣ) consists

of objects

Many objects can be said to be of the same type

or class

⚫ My bank account, your bank account, Bill ‘s bank account ,Diana’s Bank Account…

(24)

Objects and Classes

⚫ Class

⚫ Visible in source code

⚫ The code is not duplicated

⚫ Object

⚫ Own copy of data

⚫ (ﺔﺻﺎﺨﻟا ﺔﺨﺴﻧ)

⚫ Active in running program

⚫ Occupies memory

⚫ Has the set of

operations given in the class

(25)

Instantiation

⚫ An Object is instantiated from a Class

BankAccount myAccount;

(26)

Data Encapsulation

class Account { private: float balance; public: float withdraw();

void deposit(float amount); );

(27)

Advantages of Encapsulation

⚫ Protection

⚫ Consistency

(28)

Inheritance

⚫ Inheritance is a form of software reusability where

⚫ New classes created from existing (دﻮﺟﻮﻣ )ones.

⚫ Subclasses absorb super-classes’ attributes and behaviors, and add in their own.

(29)

Inheritance

⚫ A class which is a subtype of a more general class is said to be inherited from it.

⚫ The sub-class inherits the base class’s data members and member functions

(30)

Inheritance cont’d

⚫ A sub-class has all data members of its base-class plus its own (ﺔﺻﺎﺨﻟا ءﺎﻀﻋﻷا)

⚫ A sub-class has all member functions of its base class (with changes) plus its own

⚫ Inheritance is meant to implement sub-typing (don’t abuse it)

(31)

Example For Inheritance

Employee

Manager Programmer Trainee

Sr. Programmer Jr. Programmer Emp_n0,name,dob,qualif ication,address…… Dept_name,Proj_name,P roj_location Proj_code,Hrs,Incharge_ Detls Proj_code,Module_Code,( ةﺪﺣو ) Hours,Due_date

?

(32)

Abstraction

⚫ Management of complexity

⚫ Hierarchical classification:

• is-a relationship: inheritance • has-a relationship: containment

(33)

Encapsulation

Encapsulation facilitate us to understand and use a

data type without knowing all of its implementation

details

Separation between internal state of the object and its

external aspects

(34)

Polymorphism

The word polymorphism means having many forms.(ﺪﯾﺪﻌﻟا لﺎﻜﺷأ ﻦﻣ).

⚫ A call to a member function will cause a different function to be executed depending on the type of object that

(35)

An example for Polymorphism

Shape Area() Rectangle Area() Triangle Area()

(36)

⚫ Polymorphism

⚫ Allows you to make the derived types behave differently from their base types.

⚫ It uses “late binding” instead of “early binding”

⚫ Example: Bird Move() Goose Move() Penguin Move()

Polymorphism

(37)

Polymorphism

⚫ One interface

⚫ Multiple implementations

⚫ Inheritance

(38)

Identify the classes and its attributes for

the following systems.

⚫ Hospital management System. – Eg:Patients

⚫ School Management System. - Eg: students

⚫ College Management System. – Eg:Students

⚫ Pharmacy Management System. – Eg: Medicine

⚫ Hotel Management System – Eg: Item

⚫ Student Examination system. – Eg: Exam_Marks

⚫ Supermarket System. - Eg : Items.

(39)

Toys Sales System

Int Toy_code; Int Price; Int Description; Find_Price() Class : Toy Int Toy_code; Int Amount; Int Pur_Date; Find_Date_of_Purchase() Class : Purchase_Slip Int BillNo; Int Toy_code; Int Date; Find_Date_of_Bill () Class : Bill

(40)

.NET – What Is It?

⚫ Software platform

⚫ Language neutral

⚫ In other words:

.NET is not a language (Runtime and a library for writing and executing written programs in any compliant language)

(41)

What Is .NET

⚫ .Net is a new framework for developing web-based and windows-based applications within the Microsoft

environment.

⚫ The framework offers a fundamental shift in Microsoft strategy: it moves application development from

(42)

.NET – What Is It?

Operating System + Hardware .NET Framework

.NET Application

(43)

Base Class Library

Common Language Specification

Common Language Runtime ADO.NET: Data and XML VB VC++ VC#

Visual Studio.NET

ASP.NET: Web Services and Web Forms

JScript

Windows Forms

(44)

The .NET Framework

.NET Framework Services

⚫ Common Language Runtime

⚫ Windows® Forms

⚫ ASP.NET

⚫ Web Forms

⚫ Web Services

⚫ ADO.NET, evolution of ADO

(45)

Compilation in .NET

Code in VB.NET Code in C# Code in another .NET Language

VB.NET compiler C# compiler Appropriate Compiler

IL(Intermediate Language) code

CLR just-in-time execution

(46)

J2EE and .NET

Execution Engine J2EE

Java source code compiles into machine-independent byte code

Runtime Environment : JVM .NET

Any compliant language compiles into MSIL Runtime environment : CLR

Both JVM and CLR ,support services, such as code

verification, memory management via garbage collection, and code security

(47)

J2EE and .NET

Language Support

J2EE

Tied to Java

Supports other languages via interface technology .NET

Language independent

Supports any language if mapping exists from that language to IL

(48)

J2EE and .NET

Tools Support

J2EE

Can employ any number of tools

Pro :Developer has a great deal of choice

Con :Difficulty in choosing a right tool for a given job

.NET

References

Related documents

The form is prescribed by the Rule on content and form of Financial Statement for voluntary pension funds management companies (“Official Journal of RS”, no... Corrected

l Trial Balance is prepared to check the arithmetical accuracy of the ledger posting, it helps in preparing financial statements; it helps in locating accounting errors; helps

(a) assist in the documenting of the incident and preparing the incident report (b) assess the implications for an affected student’s study and assessment program (c) under

Broker shall deliver to Owner, within 30 days after the end of the month in which this Agreement is terminated, any balance of monies due Owner or tenant

28 The LIF issuer will make a lump sum payment of the entire LIF balance if the owner applies to it with written evidence that the Canada Revenue Agency has confirmed that the

Note: If a page break is not required between Balance Sheet and Income Statement accounts, print one Trial Balance Worksheet report with All as the Account type. 2 Column

kognitivna lingvistika, kognitivna gramatika, (radikalna) konstrukcijska gramatika). Stoga gore navedene razlike u upotrebi termina semanti~ka tipologija nisu nipo{to stroge

21 Interior Jamb Liner Interior Side Stop Balance Shoe Shoe Balance Cam Flat Blade Screwdriver Unlocked Position Locked Position Jamb Liner. Insert flat blade screwdriver into cam