Sie sind auf Seite 1von 12

Luke Barnes

Student I.D S0510054

Page | 1

Programming Theories

Program: (computer science) a sequence of instructions that a computer can interpret and execute; "the program required several hundred lines of code"

http://wordnetweb.princeton.edu/perl/webwn?s=computer%20program

Object Orientated Programming:


06 September 2011 Unit 6 & 15 Software Design And Object Orientated Programming

Luke Barnes

Student I.D S0510054

Also known as OOP, object oriented programming is based around the concept of reusability and Maintenance. It uses a different procedure to other forms of programming by classifying programs as objects rather than procedures. Page | 2OOP places more control in the hands of the user by allowing and even encouraging, the user to place data in locations that make it not directly accessible by the program, thus with the effect of fewer bugs and glitches. These can be caused when data is made readily accessible to the programming in its entirety, otherwise known as global.1 This is a strong advantage for OOP as it can save many possible issues from occurring and makes the programme safer from viruses.

Encapsulation: In OOP encapsulation has two meanings, which can be related but also wholly separate. Sometimes it can involve a combination of the two meanings.2 In one meaning encapsulation is seen language as a way of constructing a mechanism or code in order to restrict access to objects, or in other forms of programming, procedures (see above). Essentially, it works like a key to prevent unauthorised users from modifying programs such as components etc. so would be seen as a security feature, by restricting access. However, encapsulation can also refer to the grouping or bundling of Data with other objects that operate on The Data itself. Encapsulation is seen by some as the defining feature of Object Oriented Programming, (whether with the singular use of the first meaning or in conjunction with the second). Users who prefer to see the second definition as the only, define it as such by showing that hiding components from the program is not an automatic process or one that can be overridden, therefore classing it as a separate action.

06 September 2011

Unit 6 & 15 Software Design And Object Orientated Programming

1 In Laymans Terms, a glitch can have far reaching effects with possibly dire consequences if it is global, as it means that a programme is able to access all data along with any bugs and/or viruses affecting the whole programme

2 A language mechanism for restricting access to some of the object's components. A language construct that facilitates the bundling of data with the methods (or other functions) operating on that data.
http://en.wikipedia.org/wiki/Encapsulation_%28object-oriented_programming%29

Polymorphism: In OOP polymorphism is essentially the ability to morph into many different forms. It is a form found in OOP that enables the programmer to use a universal interface to control different aspects of code and apply them across a wide range. Inheritance: Inheritance used in OOP refers to the sectioning and re-use of code. The advantage of this is that it means an object can be created with specific distinguishing features and reused, making coding easier as the programmer is not required to rewrite code for every object. One form of Inheritance is classical inheritance. This is when an object (in this form known as a class), takes its attributes from another. (Known as the parent, super or base class). When this happens the derived class is known as the sub or derived class. These inherit the distinguishing features (such as algorithms) from the parent class. For example:
Person Name D.O.B Gender +getname +Getdob +getgender +talk

English

+new

In this diagram we see that the sub-class (below) has inherited from the parent class in that it is defined as person. This means that automatically it has a name, a D.O.B (Date of Birth) and a gender. This saves the programmer from having to re-write the code to reflect this, and so we see inheritance of these features. The Form we see here is known as single inheritance. This is when the derived class is derived from only one parent class. There are other forms of inheritance known as Multiple, Hierarchical, Multilevel and Hybrid Inheritance.

However, whilst a popular, reliable and productive method for use in programming, there are disadvantages to inheritance. Singularity If a derived class is to inherit its main feature from a super or parent class then it is locked to the traits of that class. This can be avoided to some degree by creating a separate parent class for the derived class to also inherit from. This is known as multiple inheritance but is still flawed as it can only inherit from each class once. (I.e. if a class inherits from student and employee classes it cannot have two jobs or two different courses). Static a derived class in inheritance is a fixed point so for example, a student class cannot move to employee class and still remain in the person class. This means the programmer is unable to change the nature of derived classes. Vulnerability If a person is given access to a derived class then they essentially have access to the parent class of that object and can therefore make changes. This can have disastrous effect as the programme code could be changed in many different ways not intended by the original programmer. Despite these Flaws however, inheritance is a well-used method In OOP. Object Oriented Programming altogether, is seen as a concise and reliable method of programming. It is centred around reliability and maintenance, and due to methods such as polymorphism and inheritance that enable the programmer to reuse code and improve ease of maintenance, it delivers strongly on both fronts.

Event Driven
Event driven programming is accurately titled. This type of program is strongly associated with the Windows Operating system and relates not to the structure of a program, but to how it responds to user input.

User input relates to specific actions taken by the user of the system. This could relate to user input such as Human computer Interaction (HCI), or input from messages and instruction received from other programs. For example on the Windows operating system user interaction could be something as simple as clicking on the start button. This would result in the start menu appearing, and therein lies the function of event driven programming. The object is the written procedures and how they must respond and relay information to input. This example of use within the Windows operating system is a good correlation to the fact that many event driven programs are GUIs (Graphic User Interface), such as Windows, Apple or Linux operating systems. The Advantages Of event driven Programming are many:

It allows programming for more interactive programs. Almost all modern GUI programs use event driven programming. It can be implemented using hardware interrupts, which will reduce the power used by the computer. It also allows sensors and other hardware to easily interact with software. Disadvantages are still present however: For simple programs, event driven programming is often more complex and cumbersome than OOP. The flow of the program can be less intuitive to the user. Event Driven Programs are not Thread safe

Due to event driven programming operating system such as Windows, Apple or Linux the ability to use a computer has become much more common. Before such methods a computer would need to be provided with a precise piece of code purely to initiate a single action. Whereas with todays programming it is far easier for the common user to operate applications.

Procedural
The Idea of procedural programming is to have a goal and focus on getting to it one step at a time. It is a very concise method of programming and requires steps that lead toward the required end result which must be followed. If any are missed then the end result is not the one that is desired. Procedural programming can be useful in testing when the act of use is concerned with the purpose of running and testing a program with the help of certain loops and branches being utilized. Procedural can be useful in many situations with several advantages. Its ease of use enables the user to re-use the same code at different places in the program without copying it. It is easier to keep track off as the user need only

follow the steps taken to trace past actions.

It uses less space than OOP, and has the ability to be strongly modular or structured. However, as with event driven and Object Oriented Programming there are still disadvantages to consider. Unlike OOP, Data is global, so there is no security for data. It can be difficult to relate with real world objects, and Importance is given to the operation on data rather than the data. Procedural Programming can also be separated from OOP in other ways, as its focus is to break down a programming task into a collection of data structures and subroutines, whereas in object oriented programming it is to break down a programming task into objects. Both methods can be applicable for complete a specific programming task. The most popular programming languages usually have both OOP and procedural feature.

Choosing the correct programming language


When creating an application/program there are a number of things to consider; the variables that must be taken into account are: operating systems (such as Windows or Linux), the platform, (web based, desktop or handheld), whether training will be required to use it and if so, what kind, the ease of use, and what maintenance requirements will be. So, if a handheld device were the example, what methods would the programmer be expected to take? Firstly, the application must be suitable for use in a handheld environment. (It should run smoothly and within the capabilities of the device). It should be visually suited to the device, for example for use on a Samsung Galaxy S; it should match the layout and look good on the Super AMOLED 4 inch Touch screen. Training - Will the program require specialist knowledge to use or be simple? This would vary slightly depending on the previous decision. For example to continue the handheld device theme (such as the Galaxy S) the answer is likely to be no. However on a web based or desktop application the possibility is much more likely. This must be taken into account with the user requirements as a simple to use program may be specified. All of these factors have an impact on the programming language that will be used. For instance, if the program is intended to web based, then javascript would likely be the best choice for the programmer to use. If it is going to be used on a Windows System then VB.Net would be the potential best option. The first thing a potential developer would need to consult is the development life cycle.

Gather user requirements This refers exactly to what it says. The programmer must find out exactly what the user wants before they begin to code an application. This could mean things such as which operating system the user will be running on, which key features they will need to use and how easy it will be for them to use. Obviously the code that will be used here will vary greatly based on the requirements from the user. There is the aforementioned platform (Windows or Apple etc), but also options within the program. For example if the user wishes to add or remove stock on a stock checking program then serializaton will be required. (http://en.wikipedia.org/wiki/Serialization)

Create specification This will be the information gathered from the user about the programs requirements represented before the design is created. This is very similar to the User Requirements stage and will go into more detail on subjects such as the design principals and structure. This will obviously mean that code has to be incorporated to meet the rest of the requirements to make it functional and visibly attractive, whic will be key to the next step. Create design again, due to the title the nature of the process is fairly obvious. The design will be created usually by first creating a draft and selecting colour schemes, layout etc. The finished design should look good and incorporate all the user requirements. Code here, will affected in ways such as what sort of positioning of certain boxes and suchlike. It also could be affected by factors such as the amount of buttons that are on forms. (i.e. a sleek look would have fewer buttons and so not require as much code for them as one with lots). Write programs obviously, this means that after the design is created, the programming will be written. It must be well coded, and stay true to the design. The programmer should also try to be neat. So regions would be a good start

and regular detailed commenting would be another step in the right direction. Test Programs - This will require thorough testing to make sure that there are no bugs or glitches in the system and that everything works as it should. If there are, then certain code may need to be replaced, corrected or re-written to fix errors. This is all part of the cycle as the program will not be expected to run perfectly first time. System Maintenance This is the final step. If a program is well written then it should work with as little need of maintenance as possible. However, a better written program will be easy enough for users other than the programmer to be able to perform maintenance on with the regular aforementioned comments left to help understand how it has been written. If it is complex and many layered then simplicity may not be possible. This will also be determined by how well laid out the code is and whether the programmer has used complicated, or clear methods of writing the program.

Sequence, Selection and Iteration


There are three different structures when coding. These are (as the title states) Selection, Iteration and Sequence.

Sequence
Sequence refers to an ordered execution of statements (code). This generally refers to the order you see on screen in programs such as Visual Basic Studios, meaning that the code will run in the order it was written. In other, more complex programs this is not the case, as other methods are more frequently used such as the aforementioned iteration or selection.

Below is an example of sequence coding

Dim oLottery As New Lottery Dim numbers() As Integer numbers = oLottery.getNumbers

Selection
In selection one of a number of statements is executed depending on the state of the program. This can be expressed with keywords. (i.e. If, then, when, else, endif.)

Selection is aptly named. It essentially means that different lines of code are selected depending on the action taken by the user. Selection is usually done by If statements i.e. minus the cost of product A if two or more are purchased (Buy two get one free)

Below is an example of Selection

If type = "Add" Then lblDisplay.Text = Ocalculation.addNumbers(temp, n2) 'Ocalculation.addNumbers is adding whatever number 'from the first number temp to the seconds number n2

What we see in this example is a calculator. I f the button Add is pressed after the first number is pressed then two selected numbers are added together.

Iteration
Iteration refers to repetition. It means that a particular piece of code will loop as long as necessary until its met the criteria or target there are two methods that can be used to create iteration. Method one is the for loop which is when the programmer knows the amount of times the code must loop. The advantage of this is a reduced requirement for memory. The second method is until which is when the code will loop until it has met the criteria or target described. Below is an example of Iteration

For j = 0 To 5 'loops 6 times If n = numbers(j) Then 'checks to see if the new value has already been picked check = True 'sets check to true if needed Exit For 'if number found quits for loop to pick a new random number Else 'if number does match one already picked check = False 'sets check to false End If

It is very useful for a programmer to have different data types available for use in an application. There are several types such as, String, (which can consist of both letters and numbers) Integer, (which are purely numbers), Double, (which includes a decimal point) and Date which clearly, refers to a date. The main benefits of having a wide array of data types like this available are that accuracy in code will be improved, and will be more efficient by reducing waste. It does this by telling the code what to look for, which also means that errors can be found more easily along with more efficient use of memory. It will also allow the programmer to write application code without reimplementing standard data types. The Data Dictionary below will give examples of the outlined data types along with others. String Integer -

Double

With mainly integers space will be saved which could help performance for use on some platforms. Another benefit includes suitability for use with calculations as integers allow only numbers. String as an option allows the user to include both letters and numbers but is unsuitable for use with calculations. For example if a user tried to add 1 and 1 together through string, then the answer would appear as 11. The added downside with string is that it is not very size efficient but does allow the user to use different characters together such as 3 and I. Doubles are used when a decimal point is required. These are good for applications that relate to things such as pricing tools or stock checkers. They allow numbers along with decimal points but not letters which enables the programmer to specify and save space

The advantages of having these different data types available are that the programmer is granted choice. This enables them to create a better fitting application for the intended platform so if a programmer were to develop an application based solely on numbers then they could simply use integers to save space rather than string which would be excessive and unnecessary.

Data Dictionary

Size (Bytes) Example Comment String 10 Phil 0 to approximately 2 billion Unicode characters Integer 4 12 2,147,483,647 Double 8 1.4 4.94065645841246544E-324 Char (Single Character 2 A 0 through 65535 Decimal

12 1999999.5 0 through +/-79,228,162,514,264,337,593,543,950,335 Boolean 4 True True/False Byte 1 17 0 through 255 Date 8 #1/1/2012# 0:00:00 (midnight) on January 1, 0001 through 11:59:59 PM on December 31, 9999 Long (Long Integer) 8 1234567899 9,223,372,036,854,775,808

Das könnte Ihnen auch gefallen