Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Types of Data Fundamental data type (atoms, primitive) –integers, characters Data structures- fundamental data types grouped in a particular way –Employee.

Similar presentations


Presentation on theme: "1 Types of Data Fundamental data type (atoms, primitive) –integers, characters Data structures- fundamental data types grouped in a particular way –Employee."— Presentation transcript:

1 1 Types of Data Fundamental data type (atoms, primitive) –integers, characters Data structures- fundamental data types grouped in a particular way –Employee record name salary address

2 2 Methodologies A methodology deals with the arrangement of the data and the algorithm Monolithic (block) Structured (procedural) Object Oriented (encapsulated)

3 3 Why have different methodologies evolved? Not for reasons of functionality Reduce code cost –To support development in teams –To reduce the possibility of errors –To reduce the cost of maintenance by making the program easier to understand –To support reuse of code (if code is written correctly) –To protect the integrity of data

4 4 Monolithic-Company example, sole trader Functions: One person does everything, there is no need for formally defined heirarchy/ rules/ procedures,etc. So may not have any distinct methods (blocks) Data: One data store (filing cabinet) is used for everything

5 5 Structured- Company example, small business Functions: Employees have job descriptions/ titles therefore they can be replaced/ retrained with little problem. So there are distinct functions/ methods (workOutVat, sendInvoice, makeSale) Data: Data is still stored in a filing cabinet which everyone can access (this allows unchecked access to data)

6 6 Object Oriented- Company example – multinational –Functions: Employees have job descriptions. Employees are grouping according to their task (e.g. all sales staff are put in the same room). Functions are grouped with the employee (Accountant – calculateTax, calculateIncome: SalesManager – makeSale, sendAdvert) –Data: Filing cabinets are the property of a staff group and access to these cabinets is controlled by members of the group (e.g. if the production manager wanted sales figures for this month they must contact a member of the sales group to unlock the file and get the data). Members of the group can therefore decide whether to permit or deny access to data.

7 7 Object Oriented Program Object Oriented means a program uses objects to carry out its task. It creates objects (either automatically or explicitly), stores data in them, gets objects to carry out tasks, etc. A program therefore consists of a group of objects which can communicate with each other. These objects are created from classes. An object oriented program is written using classes to describe the objects that will be created when the program executes. So an object oriented program consists of one or more classes.

8 8 Object Oriented Program When an Object Oriented Program is executing it consists of a main object, which is started first, and possibly other objects which are created by the main object or the runtime environment. The main object uses the other objects in the program to carry out the relevant tasks.

9 9 Object Oriented Program To write an Object Oriented Program 1. Need to define main class 2. Need to identify classes the main class would use (these classes in turn may need to use other classes and so on) and write them if necessary Main class Class1 Class2 Class3 Class4

10 10 Object Oriented Program To run an Object Oriented Program 1. Need to create an object from the main class 2. This main object then creates all the other relevant objects and uses them Main object object of Class1 object of Class2 object of Class3 object of Class4 object of Class1

11 11 Analogy A manager (main object) creates a team of workers (objects) who in turn may create other teams of workers (objects) Each object is separate but they have a relationship with each other.

12 12 Analogy E.g. manager object can order worker object to perform task but worker cannot order other worker to perform task unless that worker controls them. Each object controls access to their data E.g. work will divulge phone number (public information) but not ATM password (private information)

13 13 Analogy Manager worker2 managed by manager worker1 managed by manager worker3 managed by worker1 worker4 managed by worker1

14 14 Data access in an object To get access to data in an object you can do the following: 1.Contact a function (called a method in OO) in the object which will get the data for you 2.Obtain the data directly from the object without having to go through a method (this goes against the idea of OO but is necessary on rare occasions). You MUST minimise these scenarios. If you want to use 1 declare a piece of data as being private For 2 declare a piece of data as being public

15 15 Data access in an object When writing a class must make a decision for each item of data/ function. –Should item be public/private? Guideline is declare element private unless convincing reason otherwise. Should only declare data as public in exceptional circumstances

16 16 Encapsulation Protecting data by keeping it among only a specific predefined group of functions is called encapsulation (aka data hiding). Why is it important to protect data? Imagine a variable which holds an age. If other parts of the program are free to alter the age they may alter it incorrectly (e.g. you may have a negative age). When the pension calculator program runs into a negative age unpleasent things are going to happen. However if no one can change the age without having the change approved then mistakes can be avoided.

17 17 Programming Language A programming language supports a methodology, it does not enforce it (e.g. you could use an oo language to write a non-oo program) Need programmer discipline or written guidelines (pattern)

18 18 Entry point Every program has an entry point. Could be: –First instruction encountered –A single named section of the program (e.g. ‘main()’) –Multiple named sections of the program (e.g. start, init, paint)

19 19 Flow of control Which instruction is executed next? This is called the flow of control of the program Some programs work sequentially, i.e. the next instruction is the one following the current one or the one named in a jump Some programs are event based, i.e. there are several possible events defined and different instructions associated with each. An example of an event would be a button being pressed.

20 20 Errors Syntax errors – mistake in grammer or spelling – picked up by the compiler Algorithmic error – program will compile but will not work as anticipated due to mistake in code – picked up by the programmer/ tester Runtime error – invalid operation, not noticed by compiler (e.g. divide by zero) – picked up by runtime environment (Java is a friendlier runtime error handler than other programming languages)

21 21 Phases involved in developing an Object Oriented program Decide what objects there should be (if any) Write the definition for these objects Write the ‘main’ program (class) which creates and uses the relevant objects


Download ppt "1 Types of Data Fundamental data type (atoms, primitive) –integers, characters Data structures- fundamental data types grouped in a particular way –Employee."

Similar presentations


Ads by Google