Class - Shawlands Academy

advertisement
Software Development
Chapter 3
Software Development Languages
& Environments
Content statement
Higher
Advanced Higher
Description and comparison of
procedural, declarative and
event-driven languages.
Description of object-oriented language.
Comparison of object-oriented with
procedural, declarative, event-driven and
low level languages.
Explanation of the trends in language
development (low level to high level, 4th
generation).
Description of the use of module
libraries.
Description of the use and advantages
of Computer-Aided Software Engineering
(CASE) tools
Background
►
►
►
►
►
The fist object oriented language was called Simula 67
It was developed in the 1960’s by the Norwegian Computing Centre
Simula 67 contained most of the important concepts and techniques
used in present day object-oriented languages
Research then progressed and led to languages like C++, Visual Basic
and many others
The popularity of such languages was enhanced by the increasing use
of GUI’s and windows applications
Conventional Programming
Conventional methods of programming used imperative languages,
where programs were written in terms of procedures
► Programs were sequential, running to completion branching and
loping according to the programs instructions
► A flaw in this type of program was that large programs became
complex and unmanageable
► Also global variables could be accessed and changed during execution
so results might no be valid
►
Modern Programming
Today programming is done in and for a windows environment
► Windows is an event driven environment and user interaction is
required to represent the programming
► Procedural languages do not possess the necessary constructs to deal
with this style of programming and are unsuitable for windows
applications
► Object-oriented programming techniques overcome these difficulties
and make it easier for the programmer to implement good
programming practices
►
Object-Oriented Programming
►
►
►
►
►
This is a programming methodology
It compels the programmer to think in a different way about
software and its development
OO programming enables the creation of software that can be
more readily understood and shared
OO programming directly models the program and is centred
around objects and data associated with them
The OO language model makes use of:
 Objects
 Classes
 Inheritance
 Encapsulation
 Polymorphism
Objects
An object is a logical unit that contains both data and the code
that manipulates it
► The 2 are regarded as a single unit
► Objects steams from techniques with attempting to solve reallife events employing everyday objects
► Objects share 2 characteristics, they have:
 A state (data)
 A behaviour (operations)
►
Object
State
Behaviour
Dog
Size, name, colour, breed
Barking, playing, sniffing,
hunting
Car
Make, model, colour,
engine size
Accelerating, braking,
reversing, gear changing
Desk Characteristics
►
A desk
 You know where it is, it has a certain size and colour
 If we move the desk we change the location property, if we
paint it we change the colour property
 When we change the attributes of a desk we don’t change
the fact that it is still a desk
Object Characteristics
Windows objects contain 2 parts:
 Attributes (data)
 Operations (methods)
► Here is a schematic view of an object
►
Objects communicate with one another using messages
Classes
►
►
►
►
►
Objects of the same kind share many characteristics
 A car is just one of many cars
A Blueprint can be produced to accommodate objects, such a
blueprint is called a Class
Using OO terminology a car object is an Instance of the class of
objects known as cars
A main class or Super-class can have Sub-classes where all sub-classes
have common features based on the super-class
The art of OO programming is determining the best way to divide a
program into classes speeding up the development time and
producing fewer lines of code meaning less errors and lower
maintenance costs
Car Example
Suppose there exits a class called Car that contains instances of types
of cars, such as four-wheel drive, saloon
► The class car would become a super-class and the various types of car
become sub-class
►
Libraries
OO Languages depend greatly on the concept of Class Libraries
► These are sets of classes that can be used by developers as common
building blocks for complex applications
► This is like the idea of module libraries used in procedural
programming
►
Inheritance
►
►
►
►
►
►
Objects of the same kind share many characteristics and belong
to a specific class
It is possible to redefine a new type of object from an existing
class by adding additional features without modifying the
original class
This opens up the possibility of reusing existing code and is
known as Inheritance
Reuse of code is one of the most important features of OO
languages
OO Programs are easier to modify
If an error is found and fixed in the super-class it is
automatically fixed in all derived classes
Desk Example
If we create a class called Furniture and describe it then the
desk can be made a member of this class
► We can also add another class called table
► Both desk and table will inherit all the attributes and operations
of the class furniture with additional features
►
Encapsulation
►
►
►
►
►
►
Objects contain data together with operations that can be
applied to data
In OO Programming objects interact with each other by the use
of Messages
The only aspect that an object knows about another object is
the object’s Interface
Good design means that no direct access is allowed to an
objects data or the content of an object’s methods
You can use an objects methods but not interfere with them,
meaning that an object can not change the internal state of
other objects.
This is called Encapsulation c
Polymorphism
Two or more classes derived from a super-class are said to be
polymorphic
► Polymorphisms allows 2 or more classes to respond to the same
message in different ways
►
Super-class
Sub-classes
Each sub-class responds to the draw message in a different way
by drawing different shapes
Pupil task
A national chain of fitness clubs is having a new program created to
process members‘ details. The most common object in the program
will be a member's record.
(a) Describe how an object-oriented language would use objects and
methods to implement such a program.
(b) Describe one operation that might be performed on the member
object.
(c) It is suggested that an object-oriented language might ensure a
shorter implementation stage and easier maintenance than a
procedural language.
Explain why an object-oriented language might ensure a shorter
implementation stage.
Answers
(a) The member would be an object with the attached data items
(encapsulated) such as membercode, forename, etc (1). Functions
known as methods would allow the data items of the code to be
manipulated (1).
b) • Delete a member
• Add a new member
• Display/print/copy
• Any other acceptable answer
(c) No need to write/define all the methods (1) since they can be
inherited for the new object (1) reducing the amount of code needing
to be entered.
Or
Errors detected in a superclass mean subclasses will operate
correctly (1) requiring limited new coding.
Existing class libraries may exist with the necessary data and
methods already coded (1).
Procedural Languages
In the procedural language the program is considered as a series of
blocks of code that process collections of data
► Programs carryout processing according to a defined sequence of
events until the program terminates
►
Similarities of Object-Oriented and Procedural:
 OO languages have all the high level control structures for
iteration and selection available to procedural languages
 OO languages operate by changing values of variables by
using assign statements
 Both languages are problem specific
Differences
►
Differences of of Object-Oriented and Procedural:
 Object-Oriented concepts are harder to learn
 In procedural language a program module is a free standing
unit that can be compiled and executed. In OO language a
module is always part of a hierarchy
 In OO programming data and code are not regarded as
separate, both are encapsulated into an object that consists of
data and operations
 Assignment statements may look the same but their
interpretation is different
 If a program written in a procedural language encounters a
problem and crashes that is the end of the program. In OO
language if an error occurs in the code for a specific object
then only that object will be affected, the program will
continue to operate
Declarative Languages
Declarative language treats the computer in an entirely different way,
the computer is treated not as a machine that processes data but as
one that can perform logic and produce answers
► The programmer declares the result to be achieved, rather than tell it
how to achieve the result
► In declarative languages the programmer declares the relationships
between items
► Most declarative programming is carried out in a version of Prolog
►
How Declarative Works
A declarative program consists of a database and a set or rules
► The database and the rules are given to a program called the
Interpreter
► The program sets the goals and the interpreter searches for the
goals
►
Similarities of Object-Oriented and Declarative:
 Because Prolog always operated on a database there is a
mechanism built into it for searching the database. This is the
case with OO languages where the searching process is part of
the object
Differences
►
Differences of of Object-Oriented and declarative:
 Declarative languages have none of the rigid control
structures
 All data structures in declarative languages are dynamic, this
makes the database more effective
 Declarative languages make use of type free variables that
can represent widely different data structures
 Variables can be reassigned in OO languages but not in
declarative
 The scope of variables is within the rule it occurs in, there
are no global variables in declarative languages
 An assignment is an instruction to the computer to give a
variable a value. In declarative language this is called an
Instantiation and the same word in OO language implies
creating a new object
Event Driven Languages
With the increasing use of GUI’s new event driven languages, like
Visual Basic, have emerged to accommodate the new style of
programming
► Since GUI’s are object based then object-oriented techniques
feature in this environment
► In event driven environments the user executes an event
procedure, such as clicking a mouse, to run part of the code
► Event driven programs are also referred to Asynchronous
Programming as the computer waits for an event to occur and
responds to them as they happen
►
Event Dispatcher
►
►
►
►
►
An event driven program consists of smaller procedures that
respond to events triggered by the user
These procedures are called event handlers and are executed by a
program called a Dispatcher
The event dispatcher is called whenever an event is triggered
The dispatcher can be regarded as a large programming loop that
waits for an event to occur then responds accordingly
If an event is triggered while others are being processed then it is
put into an Event Queue and all events in the queue are processed
in order
Event Summary
►
►
►
►
►
►
Event-driven programs do not have a set sequence of
instructions to execute
Event programming an object-oriented programming are linked
in GUI systems
Languages like Visual Basic provide support for event-driven
programming through the use of objects, classes and methods
Inputs to event-driven programs come from event sources that
require individual event handlers to process them
Object-oriented programming techniques are evident in GUI
programming and work in harmony with event-driven
procedures
It is difficult to distinguish between object-oriented and eventdriven programs
Machine Oriented Languages
►
►
►
►
►
►
►
At low level the focus is on the computer rather than the problem
There is only 1 programming language that any computer can
understand and execute, that is binary machine code
This is the lowest possible level of language
An enhancement to binary was assembly code, it used simple
mnemonics to represent actions
These mnemonics varied from computer to computer as each had a
different Instruction Set relating to the processor
Machine code and assembly code are machine dependant and are
referred to as Machine-Oriented Languages
Low level languages run very fast and make efficient use of the
computers resources, however they have no high level features
available to them
Low Level Languages
►
Low level languages are:
 Machine dependant
 Difficult to program and debug
 Not complied or interpreted
 Demand a large expense of time on the part of the programmer
 Contain no high level constructs
 Execute extremely fast
 Produce lines of code that have a 1:1 relationship with machine
instructions
Machine Code
This was the first code used to program a computer
► Machine instructions were in binary form consisting of opcodes
(operational codes and addresses)
► A 16-bit instruction may have had the following structure
►
0001 000100110001
Op Code Address
The main problems associated with machine code were:
•Programs would only run on specific machines
•Low level programs were not easy to read , maintain or adapt
•Programmers found it difficult to remember opcodes
Assembly Code
►
►
►
►
►
Assembly language programming addressed the problem of
remembering all the opcodes
A mnemonic responded to the type of operation, this made
writing and debugging programs easier
Mnemonics have to be translated into machine code before the
processor can carry out instructions, this was achieved using an
Assembler
 An assembler is a program designed to produce machine
code
Assembly language programs have fast execution and make
efficient use of computer resource
An assembly code statement has a 1:1 relationship with a
machine language statement
Macro Generators
Assembly language developed further with a system that incorporated
single lines of code that were translated into many lines of machine
code
► These programs were called Macro Generators
►
High Level Languages
►
►
►
►
►
It became apparent that language development should now
include operations more suited to the application program
instead of hardware
That lack of portability between different computers was a
deciding factor in the development of HLL’s
High level, imperative languages were designed as blockstructured (procedures) and the lines of code resembled English
sentences and mathematical expressions, that were much
easier to read and debug
Each line of high level code translated into 10-20 lines of low
level code allowing programmers more flexibility
HLL had slow execution times since they had to be translated
HLL Advantages
►
The use of HLL started the programming revolution and offered
many advantages:
 The use of statements and keywords using English words
 Access to high level control structures, such as selection &
iteration
 The use of high level data structures such as arrays, records
and files
 The capability of defining types and dynamic data structures,
such as stacks and queues
The Computing Explosion
Progression through the 1960’s and 70’s seen a dramatic increase in:
 the number of programming languages
 the need to write easier and faster error-free programs
► Other notable factors in this increase were:
 Compiler techniques were becoming more refined
 Escalation of new hardware technologies
 Expansion of specialised software applications
► Programs ran with reduced efficiency but with decreasing costs and
increasing hardware speeds
►
4GL’s
4th Generation Languages
4GL’s were developed to meet the special needs of data
processing, with such applications as DB, SS and GR
► They were non-procedural and designed in a way that users
could specify the nature of the problem in a simple manner
without having to understand the computer processing
► Most 4GL’s were written for specific purposes:
 Database application tools
 End-user tools like query languages
 Report generators
 Application generators, sometimes known as RAD (Rapid
Application Development)
► 4GL’s have evolved and are now responsible for many of the
built-in features that can be access from a menu or icon in GUI
systems
►
Beyond 4GL
The terms 4GL and now 5GL are used to define stages in
computer language development
► There are various 5GL’s that exist:
 Natural language systems involved in Artificial Intelligence
 They encompass event-driven, object-oriented and GUI’s
 5GL is programming that uses a visual or graphical interface
to create source code
► With the rapid use of the Internet web-based languages were
developed, they include scripting and mark-up languages
►
Language Criteria
►
The criteria that might be used to decide if a language is popular is:
 It should be available to run on a variety of hardware
 It should be easy to learn
 It should be simple to implement
 It should require modest computer resources
 Its code should be efficient at running
Pupils task
Meetysoft is developing a new game. Level One of the game involves the
player fighting a number of identical enemies. In Level Two, there are new
enemies which have additional characteristics and features as well as
those of the Level One enemies.
(a) Meetysoft considers using a low level language, procedural language or
objectoriented language.
(i) Describe two similarities between procedural and object-oriented
languages.
(ii) Describe two advantages of an object-oriented language when compared
to a low level language.
(iii) Describe one advantage of a low level language when compared to an
object-oriented language.
answers
(a)
(i)
• Both have a range of data types
• Both have similar control structures
Any two answers − 1 mark each
2 KU
(ii)
Two advantages of an object-oriented language when compared to a low
level language are:
• Range of data types
• Range of control structures with meaningful names to control flow of execution
• Access to a range of arithmetical and mathematical functions
Any two answers − 1 mark each
2 PS
(iii)
One advantage of a low level language when compared to an objectoriented language is:
Optimization of code for faster execution/more efficient code.
Pupil task
Meetysoft decides to use an object-oriented language to implement
the game.
(i) Describe how an object-oriented language could be used to
implement a Level One enemy.
(ii) Describe how an object-oriented language would be used to implement
a Level Two enemy efficiently.
answers
(i)
Create a class for the enemies (1) and you can create as many instances of
this class as game play requires (1).
(ii) Create a new subclass for a level two enemy (1) which inherits all of the
properties and methods of the superclass (1) already defined for the level
one enemy.
OR
Only need to code the new features.
Download