Implementation - PowerPoint PPT Presentation

1 / 23
About This Presentation
Title:

Implementation

Description:

COM3082C2 - Systems Development 5 - 1. Implementation. Dr Z He. University of Ulster ... { unsigned long item_num; unsigned quantity; double price; ... – PowerPoint PPT presentation

Number of Views:49
Avg rating:3.0/5.0
Slides: 24
Provided by: desg
Category:

less

Transcript and Presenter's Notes

Title: Implementation


1
Implementation
  • Dr Z He
  • University of Ulster

2
Lecture 5 Implementation
  • Programming Paradigms
  • Types of programming languages
  • Choosing a programming language
  • Structured programming (using procedural/tradition
    al languages)
  • Object-oriented programming (OO languages)
  • Features of programming languages (procedural
    languages)

3
Types of Programming Languages
  • Very difficult to evaluate or compare
  • Can be classified in many ways
  • Application
  • Business/data processing COBOL
  • Scientist/engineer FORTRAN
  • Systems software C
  • Real-time/embedded Ada
  • Level
  • High level Cobol, Fortran, Ada
  • Low level assembly
  • Both high and low level C

4
Choosing Programming Languages
  • Selecting a language for a project depends on
    many factors
  • Select the language that has been used and is
    familiar
  • Select the language with which you have
    considerable experiences
  • Select the language the same as the existing
    systems
  • Select a language according to the type of the
    final system
  • Select the language as specified in contract
  • Select the language with supporting tools (IDE,
    project management)
  • Select a language according to the language
    characteristics expected
  • programming in small or large?
  • separate compilation?
  • Comments/data abstraction tool?
  • Module interface control?
  • Configuration management?

5
Structured Programming
  • Programs should only be built from three
    constructs
  • Sequences
  • written in order in which the statements are to
    be executed
  • Selections
  • written as if-then-else or switch-case
  • Repetitions
  • written as while-do, do-while, for

6
Structured Programming
  • Characteristics of structured programs
  • They have only one entry and exit
  • None of the constructs consists of more than
    three boxes (switch-case can be considered as a
    compound if-then)
  • The entry is at the start and the exit is at end
  • Avoid using goto statements whenever possible
  • Abstraction
  • most important idea in structured programming
  • subsystems can be seen as black boxes
  • a procedure can be seen as a black box (single
    entry and single exit)
  • three standard constructs have single entry and
    single exit
  • A definition of structured programming
  • the systematic use of (control) abstraction in
    programming

7
Object-Oriented Programming
  • Pure OOP languages
  • designed for OOP, Smalltalk, Eiffel, Java
  • Hybrid languages
  • extended to OOP, C
  • OOP languages support
  • encapsulation of objects
  • computation by message-passing
  • polymorphism and dynamic binding
  • classification (define classes of common objects)
  • inheritance and subclassing (subclasses)
  • class libraries (permits customisation and
    extension through subclassing)
  • Object-based languages
  • support some areas but not inheritance (e.g.
    Visual Basic 5.0)

8
Object Oriented Programming
  • Derived from SIMULA-67 and later SmallTalk-80
  • Pascal, C etc.
  • program contains a number of routines
    manipulating certain data structures
  • To change the state of this data, we call the
    routines passing data as parameters
  • SmallTalk, C etc.
  • Objects are instances of classes
  • Classes encapsulate common properties of a set of
    objects - data, state, operations (services or
    methods)
  • Operations change the state of the object
  • To execute an operation, we send a message to the
    object
  • So far the concepts are object-based
  • Object-Oriented - add inheritance

9
Object Oriented Programming
human being (base class
inherits from (is_a)
derived part
parent (derived class)
incremental part
10
Object Oriented Programming
  • class human_being
  • public
  • int age
  • float height
  • enum male, female gender
  • // declarations of operations on human_being
  • class parent public human_being
  • public
  • char name_of_spouse2-
  • int number_of_children
  • // declaration of operations on parent

11
Object Oriented Programming
  • class is the same as struct except that class
    supports inheritance
  • Advantages of C over C
  • Data abstraction and procedural abstraction are
    more complete (C has really only procedural
    abstraction)
  • Inheritance leads to fewer errors
  • Maintenance should be easier
  • Reuse is facilitated to a greater extent

12
Features of Programming Languages
  • Ref Bell et al, ch 10
  • Features of Programming Languages
  • Declarations
  • indicate the names allowed in the program.
  • places constraints on what you can do - type
    checking
  • e.g. In C, int n allows n to take on integer
    values.
  • e.g. The operator can be used to add integers
    or real numbers (In Ada - vectors as well)
  • The compiler knows from the variable types which
    is meant - binding
  • In object oriented programming, binding is done
    at runtime
  • Some languages do not require declarations.
    Rather the first occurrence of that variable is
    also its declaration e.g BASIC, FORTRAN. -
    Problems?
  • Explicit declarations reduces errors and makes
    programs more readable and maintainable

13
Features of programming languages
  • Types
  • New types can be declared. (enumerated types)
  • Operations on the declared type are only allowed
    if they have been defined
  • e.g. In C,
  • enum colour RED, GREEN, BLUE c,d
  • In this example, c and d can only take on the
    values given. The compiler will point out any
    deviations from this.
  • Type Checking is not always waterproof e.g. Most
    Pascal compilers allow you to treat pointers as
    integers, allowing you to directly access memory.
    (Ada is safe in this respect)

14
Features of programming languages
  • Structured Types
  • arrays e.g. int a10 declares a as an array of
    10 integers
  • Records (Struct in C)
  • e.g. In C,
  • struct person
  • unsigned long item_num
  • unsigned quantity
  • double price

15
Features of programming languages
  • Pointers
  • Good for defining dynamic structures such as
    lists or trees.
  • A pointer contains an address
  • e.g. linked list
  • struct cell
  • double value
  • struct cell next

p
p
16
Features of programming languages
  • A binary tree -the definition for a node will be
  • typedef struct item
  • unsigned long item_num
  • unsigned quantity
  • double price
  • struct item left_branch
  • struct item right_branch
  • item_t
  • Iteration
  • While
  • In C,
  • while (expression)
  • statement
  • Condition is checked first.

17
Features of programming languages
  • Do
  • cf. Repeat..Until in Pascal
  • do
  • statement
  • while (expression)
  • This time the expression is evaluated after the
    statement.
  • For
  • as in Pascal
  • for (exp-i exp-t exp-s )
  • statement
  • exp-i is the initial value, exp-t the test value,
    exp-s the step value

18
Features of programming languages
  • Selection
  • If condition then statement else statement
  • E.g. in C,
  • if (count lt MAX_COUNT)
  • count
  • else
  • printf(Overflow\n
  • count 0
  • else is optional here and in most languages.
  • case expression of
  • (list of values and actions)
  • end

19
Features of programming languages
  • In C,
  • switch (expression)
  • statement
  • E.g.
  • switch (n)
  • case 0
  • ...
  • break
  • case 1
  • ...
  • break
  • GOTO
  • Mostly allowed, but not recommended

20
Features of programming languages
  • What is wrong with GOTO? (ref Bell, Morrey
    Pugh pp 42-46)
  • not necessary
  • experimental evidence show harder to understand
  • clarity expressive power
  • ease of reading
  • checking - single entry/exit vs multiple
    entry/exit
  • Are there any arguments in favour
  • exception handling
  • performance (in exceptional circumstances)

21
Features of programming languages
  • PARAMETER PASSING
  • Most programming languages have the idea of
    procedures (functions in C) which allow
    parameters to be passed in and out of them
  • Actual Parameter is substituted wherever the
    corresponding formal parameter occurs in the
    procedure body

22
Features of programming languages
  • E.g.
  • .
  • .sz size(len,wdth,hght)
  • .
  • / Compute the height of a rectangular box /
  • double size(double length,
  • double width,
  • double height)
  • double size1, girth
  • girth 2 (width height)
  • size1 length girth
  • return size1

Actual arguments
Formal arguments
23
Features of programming languages
  • SEPARATE COMPILATION
  • This is where parts of the program can be
    compiled separately
  • E.g. FORTRAN - individual routines, Turbo Pascal
    - units, Modula-2 - modules, Ada - packages
  • C can be grouped into compilation units, which
    are then linked to produce an executable file
  • This allows use of modular programming
Write a Comment
User Comments (0)
About PowerShow.com