• 沒有找到結果。

From NOP to Procedure Oriented Programming

N/A
N/A
Protected

Academic year: 2022

Share "From NOP to Procedure Oriented Programming"

Copied!
10
0
0

加載中.... (立即查看全文)

全文

(1)

organize the code

identify the purpose of procedures (what a block of code can do)

isolate (modularize) the procedures (as individual functions)

reuse the procedures (by function calls)

You basically learned those in the C class.

(2)

Object Oriented Programming:

A New Way of Modularizing

a running computer in front of you: a computing “component”

an (interactive) program: a computing “component”

program A interacting with program B: another computing

“component”

sub-program A.1 interacting with sub-program A.2: two mini-computing “components”

What does a computing “component” need?

(3)

code: input → output

associated data

Google Search Engine

code: “search words” → “ranked list”

associated data: user profile, web snapshot, etc

String Processor

code: “string processing request” → “processed result”

associated data: string content

Object-Oriented Programming: Program by

(4)

Object Oriented Programming

Computing Component

associated data

code: input → output

Object

properties

actions (methods): message → return value (and status change)

Object-Oriented Programming: Program by Letting Objects Interact with Each Other

(5)

group related data together in design

1 / ∗ C ∗ /

2 t y p e d e f s t r u c t{

3 char dept [ 1 0 0 ] ;

4 char ID [ 1 0 0 ] ;

5 char name [ 1 0 0 ] ;

6 } Record ;

1 / ∗ Java ∗ /

2 c l a s s Record {

3 S t r i n g dept ;

4 S t r i n g ID ;

5 S t r i n g name ;

6 }

(6)

Object Oriented Programming 101-2

use the struct/class to generate objects

1 / ∗ C ∗ /

2 Record r ;

3 Record∗ r p = ( Record ∗ ) m a l l o c (s i z e o f( Record ) ) ;

4 s t r c p y ( r . dept , " CSIE " ) ;

5 s t r c p y ( rp −>name , " HTLIN " ) ;

6 f r e e ( r p ) ;

1 / ∗ Java ∗ /

2 Record r = new Record ( ) ;

3 r . dept = " CSIE " ;

4 r . name = " HTLIN " ;

(7)

don’t “do something on” the object; let the object “take some action”

1 / ∗ Java ∗ /

2 P r i n t S t r e a m ps = System . o u t ;

3 ps . p r i n t l n ( " CSIE " ) ;

4 S t r i n g s = " a , b , c " ;

5 t o k e n s = s . s p l i t ( " , " ) ;

(8)

From Noodle to Procedural to Object

NOP: spaghetti code + (possibly spaghetti) data

You can write NOP with virtually ANY languages

Some easier to NOP (e.g. assembly), some harder

POP: organized CODE + (possibly organized) data

using procedures as the basic module –maintain, reuse

action as separated procedures from data (do on the data)

C, Pascal

OOP: organized DATA + organized code (ACTION) grouped together

using classes as the basic module

action are closely coupled with data (data do something)

Java, C++ (?), C#

(9)

OOP: organized DATA + organized code (ACTION)

using classes as the basic module

action are closely coupled with data (data do something)

Java, C++ (?), C#

You can write virtually any-OP with any language

OO design: think in the OO way

OO language: help (force) you to think in the OO way

(10)

Three Levels of OO

Object-Oriented Analysis (OOA):

what the system does

from (customer/system) needs to software models

an important topic in Software Engineering class

Object-Oriented Design (OOD):

how the system does it

from software model to class diagrams

an important topic in Design Pattern class

Object-Oriented Programming (OOP):

how to implement such a system

from class diagrams to class implementations

learn from this class

this class: justfundamentalOOP

參考文獻

相關文件

(b) 0 = IV, since from left to right, the slopes of the tangents to graph (b) start out at a fixed positive quantity, then suddenly become negative, then positive again..

(b)- IV, since from left to right, the slopes of the tangents to graph (b) start out at a fixed positive quantity, then suddenly become negative, then

32.Start from the definition of derivative, then find the tangent line equation.. 46.Find the product of their slopes at there

• If the NET’s dependant(s) will arrive in Hong Kong later, the application for Dependant Visa should be submitted separately at a later stage, to Other Visas and Permits

(b) With effect from 1 September 1991, 2 posts in the rank of Principal Graduate Master/Mistress (PGM) are provided in an aided secondary school with 15 or more operating classes

This study has two stages: on the first stage, the researcher would use ‘Information ethics questionnaire’ as data collecting tool to collect data from local teachers college

•  Flux ratios and gravitational imaging can probe the subhalo mass function down to 1e7 solar masses. and thus help rule out (or

Then, based on these two logarithmically homogeneous self- concordant barrier functions and their related properties, we present an interior point algorithm for circular