software development chapter 3 software development languages & environments

41
Software Software Development Development Chapter 3 Chapter 3 Software Development Software Development Languages & Environments Languages & Environments

Upload: edgar-jenkins

Post on 25-Dec-2015

233 views

Category:

Documents


2 download

TRANSCRIPT

Software Software DevelopmentDevelopment

Chapter 3Chapter 3

Software Development Software Development Languages & EnvironmentsLanguages & Environments

Content statementContent statement

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

Higher Advanced Higher

BackgroundBackground

► The fist object oriented language was called Simula 67The fist object oriented language was called Simula 67► It was developed in the 1960’s by the Norwegian Computing CentreIt was developed in the 1960’s by the Norwegian Computing Centre► Simula 67 contained most of the important concepts and techniques Simula 67 contained most of the important concepts and techniques

used in present day object-oriented languagesused in present day object-oriented languages► Research then progressed and led to languages like C++, Visual Basic Research then progressed and led to languages like C++, Visual Basic

and many othersand many others► The popularity of such languages was enhanced by the increasing use The popularity of such languages was enhanced by the increasing use

of GUI’s and windows applicationsof GUI’s and windows applications

Conventional ProgrammingConventional Programming

► Conventional methods of programming used imperative languages, Conventional methods of programming used imperative languages, where programs were written in terms of procedureswhere programs were written in terms of procedures

► Programs were sequential, running to completion branching and Programs were sequential, running to completion branching and loping according to the programs instructionsloping according to the programs instructions

► A flaw in this type of program was that large programs became A flaw in this type of program was that large programs became complex and unmanageablecomplex and unmanageable

► Also global variables could be accessed and changed during execution Also global variables could be accessed and changed during execution so results might no be valid so results might no be valid

Modern ProgrammingModern Programming

► Today programming is done in and for a windows environmentToday programming is done in and for a windows environment► Windows is an event driven environment and user interaction is Windows is an event driven environment and user interaction is

required to represent the programmingrequired to represent the programming► Procedural languages do not possess the necessary constructs to deal Procedural languages do not possess the necessary constructs to deal

with this style of programming and are unsuitable for windows with this style of programming and are unsuitable for windows applicationsapplications

► Object-oriented programming techniques overcome these difficulties Object-oriented programming techniques overcome these difficulties and make it easier for the programmer to implement good and make it easier for the programmer to implement good programming practicesprogramming practices

Object-Oriented Object-Oriented ProgrammingProgramming

► This is a programming methodologyThis is a programming methodology► It compels the programmer to think in a different way about It compels the programmer to think in a different way about

software and its developmentsoftware and its development► OO programming enables the creation of software that can be OO programming enables the creation of software that can be

more readily understood and sharedmore readily understood and shared► OO programming directly models the program and is centred OO programming directly models the program and is centred

around objects and data associated with themaround objects and data associated with them► The OO language model makes use of:The OO language model makes use of:

ObjectsObjects ClassesClasses InheritanceInheritance EncapsulationEncapsulation PolymorphismPolymorphism

Objects Objects

► An object is a logical unit that contains both data and the code An object is a logical unit that contains both data and the code that manipulates itthat manipulates it

► The 2 are regarded as a single unitThe 2 are regarded as a single unit► Objects steams from techniques with attempting to solve real-Objects steams from techniques with attempting to solve real-

life events employing everyday objectslife events employing everyday objects► Objects share 2 characteristics, they have:Objects share 2 characteristics, they have:

A state (data)A state (data) A behaviour (operations)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 CharacteristicsDesk Characteristics

► A desk A desk You know where it is, it has a certain size and colourYou know where it is, it has a certain size and colour If we move the desk we change the location property, if we If we move the desk we change the location property, if we

paint it we change the colour propertypaint it we change the colour property When we change the attributes of a desk we don’t change When we change the attributes of a desk we don’t change

the fact that it is still a deskthe fact that it is still a desk

Object CharacteristicsObject Characteristics

► Windows objects contain 2 parts:Windows objects contain 2 parts: Attributes (data)Attributes (data) Operations (methods)Operations (methods)

► Here is a schematic view of an objectHere is a schematic view of an object

Objects communicate with one another using messages

ClassesClasses

► Objects of the same kind share many characteristics Objects of the same kind share many characteristics A car is just one of many carsA car is just one of many cars

► A A Blueprint Blueprint can be produced to accommodate objects, such a can be produced to accommodate objects, such a blueprint is called a blueprint is called a ClassClass

► Using OO terminology a car object is an Using OO terminology a car object is an Instance Instance of the class of objects of the class of objects known as carsknown as cars

► A main class or A main class or Super-class Super-class can have can have Sub-classes Sub-classes where all sub-classes where all sub-classes have common features based on the super-classhave common features based on the super-class

► The art of OO programming is determining the best way to divide a The art of OO programming is determining the best way to divide a program into classes speeding up the development time and program into classes speeding up the development time and producing fewer lines of code meaning less errors and lower producing fewer lines of code meaning less errors and lower maintenance costsmaintenance costs

Car ExampleCar Example

► Suppose there exits a class called Car that contains instances of types Suppose there exits a class called Car that contains instances of types of cars, such as four-wheel drive, saloonof cars, such as four-wheel drive, saloon

► The class car would become a super-class and the various types of car The class car would become a super-class and the various types of car become sub-classbecome sub-class

Libraries Libraries

► OO Languages depend greatly on the concept of OO Languages depend greatly on the concept of Class Libraries Class Libraries ► These are sets of classes that can be used by developers as common These are sets of classes that can be used by developers as common

building blocks for complex applicationsbuilding blocks for complex applications► This is like the idea of module libraries used in procedural This is like the idea of module libraries used in procedural

programmingprogramming

Inheritance Inheritance

► Objects of the same kind share many characteristics and belong Objects of the same kind share many characteristics and belong to a specific classto a specific class

► It is possible to redefine a new type of object from an existing It is possible to redefine a new type of object from an existing class by adding additional features without modifying the class by adding additional features without modifying the original classoriginal class

► This opens up the possibility of reusing existing code and is This opens up the possibility of reusing existing code and is known as known as InheritanceInheritance

► Reuse of code is one of the most important features of OO Reuse of code is one of the most important features of OO languageslanguages

► OO Programs are easier to modifyOO Programs are easier to modify► If an error is found and fixed in the super-class it is If an error is found and fixed in the super-class it is

automatically fixed in all derived classesautomatically fixed in all derived classes

Desk ExampleDesk Example

► If we create a class called Furniture and describe it then the If we create a class called Furniture and describe it then the desk can be made a member of this classdesk can be made a member of this class

► We can also add another class called tableWe can also add another class called table► Both desk and table will inherit all the attributes and operations Both desk and table will inherit all the attributes and operations

of the class furniture with additional featuresof the class furniture with additional features

EncapsulationEncapsulation

► Objects contain data together with operations that can be Objects contain data together with operations that can be applied to dataapplied to data

► In OO Programming objects interact with each other by the use In OO Programming objects interact with each other by the use of of Messages Messages

► The only aspect that an object knows about another object is The only aspect that an object knows about another object is the object’s the object’s InterfaceInterface

► Good design means that no direct access is allowed to an Good design means that no direct access is allowed to an objects data or the content of an object’s methodsobjects data or the content of an object’s methods

► You can use an objects methods but not interfere with them, You can use an objects methods but not interfere with them, meaning that an object can not change the internal state of meaning that an object can not change the internal state of other objects. other objects.

► This is called This is called Encapsulation cEncapsulation c

Polymorphism Polymorphism

► Two or more classes derived from a super-class are said to be Two or more classes derived from a super-class are said to be polymorphicpolymorphic

► Polymorphisms allows 2 or more classes to respond to the same Polymorphisms allows 2 or more classes to respond to the same message in different waysmessage in different ways

Each sub-class responds to the draw message in a different way by drawing different shapes

Super-class

Sub-classes

Pupil taskPupil taskA national chain of fitness clubs is having a new program created to process members‘ details. The most common object in the programwill 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.

AnswersAnswers(a) The member would be an object with the attached data items(encapsulated) such as membercode, forename, etc (1). Functionsknown as methods would allow the data items of the code to bemanipulated (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 beinherited for the new object (1) reducing the amount of code needingto be entered.OrErrors detected in a superclass mean subclasses will operatecorrectly (1) requiring limited new coding.Existing class libraries may exist with the necessary data andmethods already coded (1).

Procedural LanguagesProcedural Languages

► In the procedural language the program is considered as a series of In the procedural language the program is considered as a series of blocks of code that process collections of datablocks of code that process collections of data

► Programs carryout processing according to a defined sequence of Programs carryout processing according to a defined sequence of events until the program terminatesevents 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

DifferencesDifferences► Differences of of Object-Oriented and Procedural:Differences of of Object-Oriented and Procedural:

Object-Oriented concepts are harder to learnObject-Oriented concepts are harder to learn In procedural language a program module is a free standing unit In procedural language a program module is a free standing unit

that can be compiled and executed. In OO language a module is that can be compiled and executed. In OO language a module is always part of a hierarchy always part of a hierarchy

In OO programming data and code are not regarded as separate, In OO programming data and code are not regarded as separate, both are encapsulated into an object that consists of data and both are encapsulated into an object that consists of data and operationsoperations

Assignment statements may look the same but their interpretation Assignment statements may look the same but their interpretation is differentis different

If a program written in a procedural language encounters a problem 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 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 error occurs in the code for a specific object then only that object will be affected, the program will continue to operatewill be affected, the program will continue to operate

Declarative LanguagesDeclarative Languages

► Declarative language treats the computer in an entirely different way, Declarative language treats the computer in an entirely different way, the computer is treated not as a machine that processes data but as the computer is treated not as a machine that processes data but as one that can perform logic and produce answersone that can perform logic and produce answers

► The programmer declares the result to be achieved, rather than tell it The programmer declares the result to be achieved, rather than tell it how to achieve the resulthow to achieve the result

► In declarative languages the programmer declares the relationships In declarative languages the programmer declares the relationships between itemsbetween items

► Most declarative programming is carried out in a version of PrologMost declarative programming is carried out in a version of Prolog

How Declarative WorksHow Declarative Works

► A declarative program consists of a database and a set or rulesA declarative program consists of a database and a set or rules► The database and the rules are given to a program called the The database and the rules are given to a program called the

InterpreterInterpreter ► The program sets the goals and the interpreter searches for the The program sets the goals and the interpreter searches for the

goalsgoals

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

DifferencesDifferences► Differences of of Object-Oriented and declarative:Differences of of Object-Oriented and declarative:

Declarative languages have none of the rigid control structuresDeclarative languages have none of the rigid control structures All data structures in declarative languages are dynamic, this All data structures in declarative languages are dynamic, this

makes the database more effectivemakes the database more effective Declarative languages make use of type free variables that can Declarative languages make use of type free variables that can

represent widely different data structuresrepresent widely different data structures Variables can be reassigned in OO languages but not in declarativeVariables can be reassigned in OO languages but not in declarative The scope of variables is within the rule it occurs in, there are no The scope of variables is within the rule it occurs in, there are no

global variables in declarative languagesglobal variables in declarative languages An assignment is an instruction to the computer to give a variable An assignment is an instruction to the computer to give a variable

a value. In declarative language this is called an a value. In declarative language this is called an Instantiation Instantiation and and the same word in OO language implies creating a new objectthe same word in OO language implies creating a new object

Event Driven LanguagesEvent Driven Languages

► With the increasing use of GUI’s new event driven languages, like With the increasing use of GUI’s new event driven languages, like Visual Basic, have emerged to accommodate the new style of Visual Basic, have emerged to accommodate the new style of programmingprogramming

► Since GUI’s are object based then object-oriented techniques Since GUI’s are object based then object-oriented techniques feature in this environmentfeature in this environment

► In event driven environments the user executes an event In event driven environments the user executes an event procedure, such as clicking a mouse, to run part of the codeprocedure, such as clicking a mouse, to run part of the code

► Event driven programs are also referred to Event driven programs are also referred to Asynchronous Asynchronous Programming Programming as the computer waits for an event to occur and as the computer waits for an event to occur and responds to them as they happenresponds to them as they happen

Event DispatcherEvent Dispatcher

► An event driven program consists of smaller procedures that An event driven program consists of smaller procedures that respond to events triggered by the userrespond to events triggered by the user

► These procedures are called event handlers and are executed by a These procedures are called event handlers and are executed by a program called a program called a Dispatcher Dispatcher

► The event dispatcher is called whenever an event is triggeredThe event dispatcher is called whenever an event is triggered► The dispatcher can be regarded as a large programming loop that The dispatcher can be regarded as a large programming loop that

waits for an event to occur then responds accordinglywaits for an event to occur then responds accordingly► If an event is triggered while others are being processed then it is If an event is triggered while others are being processed then it is

put into an put into an Event Queue Event Queue and all events in the queue are and all events in the queue are processed in orderprocessed in order

Event SummaryEvent Summary► Event-driven programs do not have a set sequence of Event-driven programs do not have a set sequence of

instructions to executeinstructions to execute► Event programming an object-oriented programming are linked Event programming an object-oriented programming are linked

in GUI systemsin GUI systems► Languages like Visual Basic provide support for event-driven Languages like Visual Basic provide support for event-driven

programming through the use of objects, classes and methodsprogramming through the use of objects, classes and methods► Inputs to event-driven programs come from event sources that Inputs to event-driven programs come from event sources that

require individual event handlers to process themrequire individual event handlers to process them► Object-oriented programming techniques are evident in GUI Object-oriented programming techniques are evident in GUI

programming and work in harmony with event-driven programming and work in harmony with event-driven proceduresprocedures

► It is difficult to distinguish between object-oriented and event-It is difficult to distinguish between object-oriented and event-driven programsdriven programs

Machine Oriented LanguagesMachine Oriented Languages

► At low level the focus is on the computer rather than the problemAt low level the focus is on the computer rather than the problem► There is only 1 programming language that any computer can There is only 1 programming language that any computer can

understand and execute, that is binary machine codeunderstand and execute, that is binary machine code► This is the lowest possible level of languageThis is the lowest possible level of language► An enhancement to binary was assembly code, it used simple An enhancement to binary was assembly code, it used simple

mnemonics to represent actionsmnemonics to represent actions► These mnemonics varied from computer to computer as each had a These mnemonics varied from computer to computer as each had a

different different Instruction Set Instruction Set relating to the processorrelating to the processor► Machine code and assembly code are machine dependant and are Machine code and assembly code are machine dependant and are

referred to as referred to as Machine-Oriented Languages Machine-Oriented Languages ► Low level languages run very fast and make efficient use of the Low level languages run very fast and make efficient use of the

computers resources, however they have no high level features computers resources, however they have no high level features available to themavailable to them

Low Level LanguagesLow Level Languages

► Low level languages are:Low level languages are: Machine dependantMachine dependant Difficult to program and debugDifficult to program and debug Not complied or interpretedNot complied or interpreted Demand a large expense of time on the part of the programmerDemand a large expense of time on the part of the programmer Contain no high level constructsContain no high level constructs Execute extremely fastExecute extremely fast Produce lines of code that have a 1:1 relationship with machine Produce lines of code that have a 1:1 relationship with machine

instructionsinstructions

Machine CodeMachine Code

► This was the first code used to program a computerThis was the first code used to program a computer► Machine instructions were in binary form consisting of opcodes (operational codes and Machine instructions were in binary form consisting of opcodes (operational codes and

addresses)addresses)► A 16-bit instruction may have had the following structureA 16-bit instruction may have had the following structure

0 0 0 1 0 0 0 1 0 0 1 1 0 0 0 10 0 0 1 0 0 0 1 0 0 1 1 0 0 0 1Op Code AddressOp 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 CodeAssembly Code

► Assembly language programming addressed the problem of Assembly language programming addressed the problem of remembering all the opcodesremembering all the opcodes

► A mnemonic responded to the type of operation, this made A mnemonic responded to the type of operation, this made writing and debugging programs easierwriting and debugging programs easier

► Mnemonics have to be translated into machine code before the Mnemonics have to be translated into machine code before the processor can carry out instructions, this was achieved using an processor can carry out instructions, this was achieved using an Assembler Assembler An assembler is a program designed to produce machine An assembler is a program designed to produce machine

codecode► Assembly language programs have fast execution and make Assembly language programs have fast execution and make

efficient use of computer resource efficient use of computer resource ► An assembly code statement has a 1:1 relationship with a An assembly code statement has a 1:1 relationship with a

machine language statementmachine language statement

Macro GeneratorsMacro Generators

► Assembly language developed further with a system that incorporated Assembly language developed further with a system that incorporated single lines of code that were translated into many lines of machine single lines of code that were translated into many lines of machine codecode

► These programs were called These programs were called Macro GeneratorsMacro Generators

High Level LanguagesHigh Level Languages► It became apparent that language development should now It became apparent that language development should now

include operations more suited to the application program include operations more suited to the application program instead of hardwareinstead of hardware

► That lack of portability between different computers was a That lack of portability between different computers was a deciding factor in the development of HLL’sdeciding factor in the development of HLL’s

► High level, imperative languages were designed as block-High level, imperative languages were designed as block-structured (procedures) and the lines of code resembled structured (procedures) and the lines of code resembled English sentences and mathematical expressions, that were English sentences and mathematical expressions, that were much easier to read and debugmuch easier to read and debug

► Each line of high level code translated into 10-20 lines of low Each line of high level code translated into 10-20 lines of low level code allowing programmers more flexibilitylevel code allowing programmers more flexibility

► HLL had slow execution times since they had to be translatedHLL had slow execution times since they had to be translated

HLL AdvantagesHLL Advantages

► The use of HLL started the programming revolution and offered The use of HLL started the programming revolution and offered many advantages:many advantages: The use of statements and keywords using English wordsThe use of statements and keywords using English words Access to high level control structures, such as selection & Access to high level control structures, such as selection &

iterationiteration The use of high level data structures such as arrays, records The use of high level data structures such as arrays, records

and filesand files The capability of defining types and dynamic data structures, The capability of defining types and dynamic data structures,

such as stacks and queuessuch as stacks and queues

The Computing ExplosionThe Computing Explosion

► Progression through the 1960’s and 70’s seen a dramatic increase in:Progression through the 1960’s and 70’s seen a dramatic increase in: the number of programming languagesthe number of programming languages the need to write easier and faster error-free programsthe need to write easier and faster error-free programs

► Other notable factors in this increase were:Other notable factors in this increase were: Compiler techniques were becoming more refined Compiler techniques were becoming more refined Escalation of new hardware technologiesEscalation of new hardware technologies Expansion of specialised software applicationsExpansion of specialised software applications

► Programs ran with reduced efficiency but with decreasing costs and Programs ran with reduced efficiency but with decreasing costs and increasing hardware speedsincreasing hardware speeds

4GL’s4GL’s

► 4GL’s were developed to meet the special needs of data 4GL’s were developed to meet the special needs of data processing, with such applications as DB, SS and GRprocessing, with such applications as DB, SS and GR

► They were non-procedural and designed in a way that users They were non-procedural and designed in a way that users could specify the nature of the problem in a simple manner could specify the nature of the problem in a simple manner without having to understand the computer processingwithout having to understand the computer processing

► Most 4GL’s were written for specific purposes:Most 4GL’s were written for specific purposes: Database application tools Database application tools End-user tools like query languagesEnd-user tools like query languages Report generatorsReport generators Application generators, sometimes known as RAD (Rapid Application generators, sometimes known as RAD (Rapid

Application Development)Application Development)► 4GL’s have evolved and are now responsible for many of the 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 built-in features that can be access from a menu or icon in GUI systemssystems

4th Generation Languages

Beyond 4GLBeyond 4GL

► The terms 4GL and now 5GL are used to define stages in The terms 4GL and now 5GL are used to define stages in computer language developmentcomputer language development

► There are various 5GL’s that exist:There are various 5GL’s that exist: Natural language systems involved in Artificial Intelligence Natural language systems involved in Artificial Intelligence They encompass event-driven, object-oriented and GUI’sThey encompass event-driven, object-oriented and GUI’s 5GL is programming that uses a visual or graphical interface 5GL is programming that uses a visual or graphical interface

to create source codeto create source code► With the rapid use of the Internet web-based languages were With the rapid use of the Internet web-based languages were

developed, they include scripting and mark-up languagesdeveloped, they include scripting and mark-up languages

Language CriteriaLanguage Criteria

► The criteria that might be used to decide if a language is popular is:The criteria that might be used to decide if a language is popular is: It should be available to run on a variety of hardwareIt should be available to run on a variety of hardware It should be easy to learnIt should be easy to learn It should be simple to implementIt should be simple to implement It should require modest computer resourcesIt should require modest computer resources Its code should be efficient at runningIts code should be efficient at running

Pupils taskPupils taskMeetysoft 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-orientedlanguages.

(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 anobject-oriented language.

answersanswers

(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 object-oriented language is: Optimization of code for faster execution/more efficient code.

Pupil taskPupil 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.

answersanswers

(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.