Sei sulla pagina 1di 12

Stephen Rosister (S0511437)

Unit -6 and 15

Programming Theories
In this written document I will explain the key features, advantages and disadvantages of Object Orientated, Event Driven and Procedural programming types.

Task 1
Object Orientated
This type of programming is based around objects instead of procedures. The objects, also known as data structures, are grouped instructions and data. OO was designed because there were difficulties in creating complex systems using a procedural approach. OO also offers a less number of functions compared to low level programming (procedural) which interacts directly with the pcs hardware, but because OO and procedural are programming techniques therefore it can be used at multiple levels.

Inheritance Inheritance makes the code re-usable because the OO code is split in to
classes, for example, the code for animal would be one class with all the data that every animal has; this is the parent class. The individual animal classes such as dog, cat and horse would inherit the code for animal, meaning the OO developer doesnt need to rewrite the code for animal over and over again. Each individual animal class is classes as a child. The child classes inherit everything from the parent class. Because the code is inherited by the child class the code doesnt need to be re-written.

Polymorphism When polymorphism is used in OOP the developer has the ability to
create a variable, function or object that has the ability to change its form to suit of programs. Polymorphism is nothing but a function with the same name exhibiting two or more characteristics. For example; DrawShape() Drawshape(intRadius) = Circle DrawShape(intLength, intBreadth) = Rectangle

06/09/2011

Page 1

Stephen Rosister (S0511437)

Unit -6 and 15

This code is an example of overloading, there is also another type of polymorphism called overriding; method overriding enables programmers to allow a derived class to alter the behaviours it inherited from its base class. For example,
Public Overrides Function GetRating() As Integer creditrating = Clnt(Balence) \ 100 If creditrating > 5 Then creditrating = 5 End If Return creditrating End Function

Encapsulation
In OOP, Encapsulation is a language mechanism for restricting access to some of the objects components. The data that has been encapsulated cannot be accessed unless the specific means are used. When programming there are three different levels of access: Public, Protected and Private, each one will only allow for certain codes to access them depending on their access level. Public level access, allows all classes to access the data without any restrictions. Protected data is restricted to functions of inheritance classes; for example is the first class has the code needed to access the data all the classes that inherit that class also gain access to the data. Private data can only be accessed by the classes that have the access codes to that data. Private is the highest level of protection. Objects that are encapsulated do not need to reveal all their attributes and behaviours. It should only reveal the interfaces that are needed to interact with it.

Advantages
Due to inheritance and polymorphism OO is re-usable. The code is very easy to maintain due to inheritance (see above) and it is also re-useable due to the inheritance of class from parent to child classes.

Disadvantages

06/09/2011

Page 2

Stephen Rosister (S0511437)

Unit -6 and 15

I of the main disadvantages of OOP is that it is very complex and difficult to pick up for new programmers. OOP is a high level concept therefore it takes more time to execute because many other codes run in the background at the same time. There is an increased burden

on the part of an OO developer because of the complexity and detail needed in OO code.

Event Driven
A program that responds to user input, this is determined by an event (event trigger), sensor outputs or user inputs, such as mouse clicks, timers, key presses or messages from other programs or threads.

Advantages
Event driven programming allows for a more interactive programs, almost all modern GUI programs use event driven programming, for instance the desktop of any operating system, for example Windows xp, windows 7 and the Macintosh operating systems all are event driven. The icons on the desktop must be clicked on before anything will happen. The use of Event Driven programming allows sensors and other hardware to interact with the software more easily. Event Driven programming can also be implemented using hardware interrupts so the computer will use less power. Event Driven programs integrate well with GUI and other UIs; it is also easy to set it up to receive messages from other threads.

Disadvantages
For simple Event Driven programming is often more complex and would be harder to use than other types of programming. The flow diagrams of Event Driven are usually less logical and obvious. Programs made using Event Driven Programming are memory intensive. The classes made when using this type of programming are not re-usable or are hard to implement in to other applications, it is also complex to master and is often not portable to other operating systems. Event Driven is generally only useful in GUI programming and games where you chose what happens.

06/09/2011

Page 3

Stephen Rosister (S0511437)

Unit -6 and 15

After clicking the start icon, an event driven code runs and opens the start menu.

Procedural
This type of programming, unlike Object Orientated Programming, uses procedures instead of objects. Each code must run in a certain order and cannot be re-arranged. The next stage of the code cannot start until the previous has finished. The procedures can also be knows as, routines, sub-routines, methods or functions. The functions should not be confused with mathematical functions but are similar to those used in functional programming. The procedures simply contain a series of steps that will be carried out. Any of the procedures may be called at any point during a programs execution, by another procedure or itself. Procedural programming is the most consistent of all programming languages.

Advantages
Procedural programing will run faster than Object Orientated Programming, the procedures also allow for quicker completion. This type of programming is easier to pick up for people who are new to programming

Disadvantages
Although it is faster than OOP it isnt as flexible as other types of programming. For very large programs the codes get very long and if a mistake is made the programmer will have to go through the code and find each part that is wrong and change it.

06/09/2011

Page 4

Stephen Rosister (S0511437)

Unit -6 and 15

Task 2
When choosing a programming language a number of different factors should be taken in to consideration; for example, the operating system that is currently in use, if the program is going to be web based, is the program going to be used on a desktop or a hand held device, how much will it cost to train staff so they can use the language that will be chosen and the ease and cost of maintaining the finished product.

Operating System
If a developer chose a programming language that was compatible with apple and the company or corporation that came to them for a program were using windows 7 or a Linux operating system the overall product wouldnt work and the program would have to be remade at the programmers expense. For example military applications will be written in languages such as ADA whereas windows programming is well supported by languages such as Visual Basic. The Java programming language is best suited for use in internet programs and mobile device applications such as smart phone apps and games. The Visual Basic programming language is only compatible with PC hardware that is running off a Windows operating system.

Platform (Desktop, Handheld device, Web Based)


The platform on which a program is going to be made is very important because a mobile devise will need less programming than a conventional desktop PC. The mobile applications tend to be limited to single player game mode (no online gaming capability) which means there would be no need for the code to run online gaming. Therefore without the code for online gaming the code would be shorter than games that do need the code for online gaming. If an application is being used on the internet the program would need to support many users at once because many people in the modern world have access to the internet, if an online program only had the code to support up to a few user at a time it would crash a lot because many people would want to use the site or program at the same time.

Cost to train staff

06/09/2011

Page 5

Stephen Rosister (S0511437)

Unit -6 and 15

If the staff at a programming company could all use Visual Basic, there would be no point in paying for them all to learn C#. The only reason for the staff to learn C# would be if the client wanted game programming. Also if the program was for use on mobile devices, desktops and the internet the program would have to be made in Java. When choosing a programming language the cost of training and the eventual outcome of the completed program. When training staff the company are losing money because the staff are not programming and they also have to pay for a tutor to come in and teach the staff whatever language is being used. The choice to use a language that is not first choice would be decided on the total cost of training staff and the final bill for the client when the program gets completed.

Ease and cost of maintenance


When a program has been finished the chances are there will be bugs (mistakes) in the coding; for example when Infinity Ward release a new game such as Call of Duty there will be bugs within the game that let the gamer do things that arent meant to happen. The bugs can be anything from getting out of the map to not getting hit in a game of zombies. When the bugs are found the games company need to be able to fix them; the harder it is to find, alter the code and release an update for the new code to take effect will cost the company money. If the code is easy to maintain the company will not have to spend too much time finding and fixing the bugs. For example if the game is made using OOP the bug will most probably be found and fixed relatively quickly due to the inheritance of the code. Once the first mistake has been found the changed code will be inherited by the classes and all the bugs get fixed.

Task 3 Selection
Selection statements allow a choice to be made as to which a set of statements are carried out next.
Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click Dim input As String input = txtInput.Text

06/09/2011

Page 6

Stephen Rosister (S0511437)


Dim input As String input = txtInput.Text

Unit -6 and 15

If input = "A" Or input = "B" Then MessageBox.Show("well done you typed in and " & input) Else MessageBox.Show("Why is it so hard to type an A or a B?") End If

When I enter a letter it to the text box the sequence runs and gives me a message box with a small message inside it. The message box will not appear until text is entered in to the text box.

Private Sub btnGo2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo2.Click Dim input As Integer input = CType(txtInput2.Text, Integer) If input > 10 And input < 20 Then MessageBox.Show("Well done") Else MessageBox.Show("Not so good") End If

When a number lower than ten is entered in to the second text box a message box will appear saying Not so good and if a number between 10 and 20 is entered the message box
06/09/2011 Page 7

Stephen Rosister (S0511437)

Unit -6 and 15

will appear saying Well done. The two message boxes say something different depending on what is entered in them because of the If coding.

Iteration
Iteration is a loop; there are three different types of loop coding. In for loops you know how many times the code will loop, whereas while/until loops will loop any number of time and you do not know how many times it will loop. Do loops will loop at least once but you do not know how many times after the first loop it will loop again.
Dim check As Boolean = True While (check) lstNumbers.Items.Add("looped again") End While Randomize() Dim n As Integer = Rnd() * 10 Do If n <> 8 Then lstNumbers.Items.Add(n.ToString()) Else check = False End If n = Rnd() * 10 Loop While (check = True)

A While or Do loop will loop until a condition is met. The user doesnt know how many loops will take place.

Sequence
Procedural programming is a sequence. Programs that are set in to sequences will only happen in one order and it will not skip any of the programming steps.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load cbbNames.Items.Add("Ross") cbbNames.Items.Add("Stephen H") cbbNames.Items.Add("Nico") cbbNames.Items.Add("Matt O") cbbNames.Items.Add("Liam") cbbNames.Items.Add("Kieran") cbbNames.Items.Add("Matthew R") cbbNames.Items.Add("Stephen R") cbbNames.Items.Add("Ivan")

06/09/2011

Page 8

Stephen Rosister (S0511437)


cbbNames.Items.Add("Dan") cbbNames.Items.Add("Yueharo") With cbbNames.Items .Add("Joe B") .Add("Daniel") .Add("Jack") .Add("Joe") .Add("Luke") End With

Unit -6 and 15

When a program needs to execute certain procedures such as calculations, accepting user input and outputting data; the program instructions are followed in sequence. For example when the coding above is executed the names are listed in the order that they have been entered.

Task 4
Data type String (variablelength) Integer Data size 10 bytes + (2*string length) 4 Bytes Example data 1+1=11 Data range 0 to approximately 2 billion Unicode characters. -2147483648 to +2147483647 Up to 14 significant digits Large positive and negative numbers with 28 significant digits A Date and Time Variable A Unicode value. (A code that represents characters on the keyboard) 0 to 65535 (unsigned) 0 to 255 True or False
Page 9

Whole numbers between the data range eg. 956,254

Double (Doubleprescience floatingpoint Decimal

8 Bytes

12 Bytes

Date Char (single Character)

8 Bytes 2 Bytes

Date and Time

Byte Boolean
06/09/2011

1 Byte 1 Byte

Whole Numbers Values that can only

Stephen Rosister (S0511437)

Unit -6 and 15

be True of False Every variable has a data type. This sets the type of data that will be stored and the range of values that a variable can accept. The data type will also define how the data will be formatted when displayed. Choosing the correct data type for your variables is crucial. Inappropriate types could result in excessive amounts of storage set aside when it is not needed. If a variable cannot accommodate the size of the value assigned to it, the system will crash. Data that is needed to do calculations must be placed in a numeric data type such as an integer, or single. However if you insert non-numeric data the program will crash. Code can be used to stop a user from entering non-numeric data in to s text box that will only work with numeric data; for example,
Dim n As Integer 'converts the key that has been pressed 'in to an ascii value n = AscW(e.KeyChar) 'checks to see if the key pressed 'is not a number If (n < 48 Or n > 57) And n <> 8 And n <> 46 Then 'if it is not a number then 'tells the program that the key press has been dealt with e.Handled = True ElseIf n = 46 And txtItemPrice.Text.IndexOf(".") <> -1 Then e.Handled = True 'only allows one decimal place to be entered Else If (txtItemPrice.Text.Length > txtItemPrice.Text.IndexOf(".") + 2) And txtItemPrice.Text.IndexOf(".") <> -1 And n <> 8 Then e.Handled = True 'only allows two digits after the decimal place End If End If

For instance the code above is for a change calculator user input box, the code stops the user from entering letters and other non-numeric data but it does allow the input of a decimal place, this is allowed by;
ElseIf n = 46 And txtItemPrice.Text.IndexOf(".") <> -1 Then e.Handled = True 'only allows one decimal place to be entered

06/09/2011

Page 10

Stephen Rosister (S0511437)

Unit -6 and 15

Bibliography
http://msdn.microsoft.com/en-us/library/47zceaw7(VS.80).aspx http://en.wikipedia.org/wiki/Object-oriented_programming http://en.wikipedia.org/wiki/Procedural_programming http://en.wikipedia.org/wiki/Event-driven_programming http://wiki.answers.com/Q/What_are_the_advantages_of_event_driven_programming http://www.answers.com/topic/procedural-language http://wiki.answers.com/Q/What_is_an_inheritence&altQ=Inheritence_in_oop&isLookUp= 1 http://wiki.answers.com/Q/What_is_polymorphism_in_oops http://wiki.answers.com/Q/What_are_advantages_and_disadvantages_of_OOP_'Object_Or iented_Programming'&altQ=Disadvantage_of_OOP&isLookUp=1 http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming Edexcel Information Technology Level 3 Book 1. BTEC National Karen Anderson, Alan Jarvis, Allen Kaye, Jenny Lawson, Richard McGill, Jenny Phillips, Andrew Smith Pages 166 and 173 Visual Basic .NET A complete Object-Orientated Programming Course Including Unified Modelling Language (UML) Phil Jones with a foreword by Tim Sneath of Microsoft Pages 216, 385, 439

06/09/2011

Page 11

Stephen Rosister (S0511437)

Unit -6 and 15

06/09/2011

Page 12

Potrebbero piacerti anche