1 / 21

Object oriented vs procedural vs event driven programming

Object oriented vs procedural vs event driven programming. Procedural programming. Although Java is primarily object oriented up until now all we have used it to produce is procedural code. The language C is an example of a strictly procedural language

melmer
Télécharger la présentation

Object oriented vs procedural vs event driven programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Object oriented vs procedural vs event driven programming

  2. Procedural programming • Although Java is primarily object oriented up until now all we have used it to produce is procedural code. • The language C is an example of a strictly procedural language • Object Oriented Programming(OOP) languages such as C++, C# and Java improve on this. • Procedural programming is a list or set of instructions telling a computer what to do step by step and how to perform from the first code to the second code. (A systematic order of statements, functions and commands)

  3. Procedural programming example code A simple C hello world program Note the complete lack of class It has a main method And other methods could be written but that’s it • #include <stdio.h> • int main() • { • printf("Hello, World!"); • return 0; • }

  4. Object-Oriented Concept • Object-oriented programming models the real world in terms of objects. Everything in the world can be modeled as an object. • A circle is an object, a person is an object, and a Window icon is an object. Even a loan can be perceived as an object. • A Java program is object-oriented because programming in Java is centered on creating objects, manipulating objects, and making objects work together.

  5. Object-oriented Continued Objects hold information about state and behaviour: • States are the characteristics of the object, or the words you would use to describe it, and usually take the form of is or has descriptors. A computer is either on or off, a chair has four legs, and you have a name. • Behaviours are the things the object can do, or the actions the object can perform, and are usually verbs that end in ing. You are sitting, using a computer, and reading.

  6. Object-oriented Example • For Pac-Man, there are three objects: Pac-Man, a ghost, and a pac-dot. • The ghost has states of: • colour • name • state (eatable or not) • direction • speed • and behaviours of: • moving • changing state

  7. OO Programming example: • Properties/variables (State) • Methods(Behaviour)

  8. Key features of Object Oriented Programming • Abstraction • Allows for simple things to represent complexity. • Such as objects, classes, and variables representing more complex underlying code and data. • We all know how to turn the TV on, but we don’t need to know how it works in order to enjoy it. • For example in our code we could create a TV object then ask it to turn on. We don’t need to worry about how the TV object works as long as we know it has a on method within. • Consider the scanner import – we don’t worry about how it works we just create a scanner object and use it when we want user input. • This is important because it lets avoid repeating the same work multiple times.

  9. Key features of Object Oriented Programming • Polymorphism • Allows us to use the same word to mean different things in different contexts.  • The capability of a method to do different things and take on many forms based on the object that it is acting upon. • In other words, polymorphism allows you define one interface (or class) and have multiple implementations. 

  10. Key features of Object Oriented Programming • Inheritance • Inheritance can be defined as the process where one class acquires the properties, methods and fields of another. • With the use of inheritance the information is made manageable in a hierarchical order. • The class which inherits the properties of the other is known as subclass, derivedclass, childclass and the class whose properties are inherited are known as superclass, baseclass, parentclass.

  11. Key features of Object Oriented Programming • Encapsulation • Encapsulation in Java is a mechanism of wrapping the data variables and code acting on the data methods together as a single unit. • The variables of a class will be hidden from other classes, and can be accessed only through the methods of their current class, therefore it is also known as data hiding. • To achieve encapsulation in Java we declare the variables of a class as private. Provide public setter and getter methods to modify and view the variables values. • We can re-use objects like code components or variables without allowing open access to the data system-wide.

  12. Object Oriented example code • classCow { • String size; • String sex; • public void moo() { • System.out.println("Cow says moo."); • } • } • publicclassOldMacDonald { • publicstatic void main( String[] args ) { • Cow maudine = new Cow(); An object is an instance of a class.

  13. OOD vs procedural • Procedural programming uses a list of instructions to tell the computer what to do step-by-step. • Procedural programming relies on what’s known: • Procedures: A series of computational steps to be carried out in order. • Subroutines(Also know as functions/methods): Again a series of computational steps but this time they return a value. Consider how methods work in Java.

  14. OOD vs procedural continued • The design method used in procedural programming is called Top Down Design. • Start with a problem (procedure) • Systematically break the problem down into sub problems (sub procedures). • This is called functional decomposition, which continues until a sub problem is straightforward enough to be solved by the corresponding sub procedure. The difficulties with this type of programming, is that software maintenance can be difficult and time consuming. • When changes are made to the main procedure (top), those changes can cascade to the sub procedures of main, and the sub-sub procedures and so on, where the change may impact all procedures in the pyramid.

  15. OOD vs procedural continued • Object oriented programming is meant to address the difficulties with procedural programming. • In object oriented programming, the main modules in a program are classes, rather than procedures. • The object-oriented approach lets you create classes and objects that model real world objects. • Procedural code is quicker to implement for simpler code but get’s increasingly complex and difficult to manage as the program get’s larger. • OOP allows for easy re-use code enabling faster coding and managing on larger projects

  16. In Java Event Driven A button is clicked Action listener triggered • Uses events as the basis for developing the software. • These events can be something the users are doing — clicking on a specific button, picking an option from drop-down, typing text into a field, giving voice commands, or uploading a video — or system-generated events such as a program loading. • This is an approach to programming rather than a type of programming language, it can be practiced with any programming language. • Particularly beneficial to GUI design This triggers an event Action event run A piece of code runs in response

  17. IDE(Integrated Development Environment) • Designed to provide the facilities a programmers needs for software development • IDE’s provide a text editor, debugger and compiler all in one application. • Sometimes these can have more features than we need but are generally designed to make are coding experience as pleasant, customised and quick as possible.

  18. IDE Examples • IDE’s include: • Netbeans - C, C++, Python, Perl, PHP, Java, Ruby and more • Eclipse - Java, JavaScript, PHP, Python, Ruby, C, C++ and more • Komodo - Perl, Python, Tcl, PHP, Ruby, Javascript and more • Visual Studio - Visual C++, VB.NET, C#, F# and others • Many others!

  19. IDE: Some advantages • Look and feel customisation such as themes, fonts, colours etc. • Auto compiles and runs code • Folder Structure for the project • Provide Syntax highlighting • Automatic indentation for code blocks • Line numbers • Auto code completion • Auto code for inherited members • Provide debugging functionality, identifying syntax and obvious errors • Often provide GUI builders(Drag drop systems) for increased speed • Plug ins for additional functionality + more

  20. IDE: Some negatives • Can create custom IDE code which is generalised and may not be compatible with other development software • Can cause incompatibility with other IDE’s • May require the IDE installed to run development code • Can cause dependence on IDE shortcuts, creating lazy developers • Uses greater system memory than text editors • Some require purchasing costs or licenses • Plug ins while useful don’t always provide full information about how the work

  21. Assignment 2 Guidance P2 Create a 2000-2500 word report that: • Covers findings regarding your research on the characteristics of different programming paradigms – procedural, object-orientated and event-driven programming. • Procedural should include discussions on procedures and modularity. • Object-orientated should include discussions on inheritance, polymorphism and encapsulation • Event-driven programming should include discussion on event handlers. • Your report should include an explanation of each paradigm and include comparisons MERIT Criteria - M2 An analysis of suitable IDEs. Consider the advantages and disadvantages of the common features. Why might you use an IDE over a text editor or vice versa. DISTINCTION Criteria - D2 Evaluate Java or other language source code that would be generated for an application using each of the paradigms

More Related