Presentation is loading. Please wait.

Presentation is loading. Please wait.

Structures. Procedural (Imperative) Languages Procedural languages work on the basis of explicitly telling the computer ‘how to do something’; by using.

Similar presentations


Presentation on theme: "Structures. Procedural (Imperative) Languages Procedural languages work on the basis of explicitly telling the computer ‘how to do something’; by using."— Presentation transcript:

1 Structures

2 Procedural (Imperative) Languages Procedural languages work on the basis of explicitly telling the computer ‘how to do something’; by using a sequence of commands called imperatives (as in English grammatical form of the imperative; do this, then do that,... etc)

3 Declarative Languages Declarative languages adopt a totally different programming approach, of which Prolog (Programming in Logic) is the best known example Declarative languages work on the basis of telling the computer ‘what to do’ rather than how to do it (as procedural languages do) – The programmer defines the facts and rules. – These facts and rules are then queried to see whether TRUE or FALSE

4 A Declarative Example 1age (edward 20) 2age (robert 19) 3age (flora 17) 4age (emma 17) 5age (andrew 16) 6minimum_age (motor_cycle 16) 7minimum_age (car 17) 8minimum_age (heavy_goods_vehicle 20) 9passed_test (edward heavy_good_vehicle) 10passed_test (andrew motor_cycle) 11passed_test (emma car) 12has_provisional_licence (andrew) 13has_provisional_licence (robert) 14permitted_to_drive (X V) If passed_test (X V) 15 permitted_to_drive (X V) If has_provisional_licence (X) And age (X A) And minimum_age (V L) And A>=L statements 1 to 13 are facts statements 14 and 15 are rules ? permitted_to_drive (flora car) the program uses rule 14 the answer to which is no. The program then examines rule 15 and having scanned the facts returns the answer ‘No’ to the user ? permitted_to_drive (robert motor_cycle) using rule 15 and facts 2, 6 and 13, the program returns ‘Yes’ ? permitted_to_drive (emma V) using rule 14 and fact 11 the program returns ‘car’ queries

5 Declarative Example - Key features The program statement consist of a number of facts and rules about a particular subject Program statements may be written in any sequence, making it easy to add new facts and rules Executing the program involves stating a goal to be achieved and allowing PROLOG to determine whether the goal can be achieved with the given facts and rules The route through the program does not have to be explicitly stated by the programmer. If one route fails to achieve the goal, the program has the ability to backtrack and try another route until either the goal is achieved or there are no further route to try

6 Object-Oriented (Object-Event) Languages Object-oriented programming (OOP) -sometime called object-event programming- is probably the most important recent development in programming. OOP provides a third distinctive approach to programming is quite different from either the procedural or the declarative ones. OOP is separate objects (algorithms) running together with their own data and logic OOP is based on defining attributes and behaviours(this could be a piece of code or even an item such as a lamp) and there characteristics much like we do in the real world.

7 Object-Oriented (Object-Event) Languages In chemistry this is the norm. We find a metal and we assign it attributes and behaviour e.g. size, is it a conductor etc.. OOP has two key fundamental parts Classes and Objects

8 Classes A class is a blue print for and object to fit into It is not the object itself A definition of Properties (Attributes) and Methods(behaviours ) AttributeBehaviour Sizesleep agewalk Genderjump

9 Objects Objects is created from a class It can have one to many relationship (you can make many items from one class)

10 One last thing… Don’t forget that OOP is standalone classes (Methods and Properties) that can make objects. This is called Encapsulation. Methods Properties


Download ppt "Structures. Procedural (Imperative) Languages Procedural languages work on the basis of explicitly telling the computer ‘how to do something’; by using."

Similar presentations


Ads by Google