Programming Paradigms Procedural programming Task based Revolves around
Programming Paradigms • Procedural programming • Task based • Revolves around writing functions (procedures) to accomplish an overall goal • Supported by early programming languages • C, Cobol, Fortran, Basic, … • Object Oriented programming • Information (data) based • “Objects” represent both data and its manipulation • Supported by many modern programming languages • C++, Java, Python, Java. Script, … Professor John Carelli Kutztown University Computer Science Department
Procedural programming • Task-based approach to programming • Problem is broken down into a series of (sub)tasks • Procedures are written to accomplish each task • Data (information) manipulated by the procedures • Procedures are assembled and run to accomplish overall goal • Like a recipe • Advantages • Intuitive, can lead to fast development • Disadvantages • Large/evolving projects can result in code that is difficult to maintain/modify • Simple changes can affect many sections of code Professor John Carelli Kutztown University Computer Science Department
Object Oriented Programming • Object-based approach • Focus is on defining data types • And procedures for manipulating the data • Advantages • Objects are self-contained • Insulated from changes to other objects • Leads to better-organized, more easily supported code • Disadvantages • Less intuitive, requires more planning Professor John Carelli Kutztown University Source: Pearson Education, Inc.
Features of OOP • Encapsulation • data stored in module “objects” • accessed via “methods” • Polymorphism • method behavior can depend on usage • Inheritance • parent/child relationship • child “inherits” properties of parent Continued … Professor John Carelli Kutztown University Source: Pearson Education, Inc.
Features of OOP - Encapsulation • Data stored in modular blocks called classes • Data accessible via procedures also contained in the classes • Internal data not directly accessible (only through procedures) • Advantage: changes can be localized in an object • Will not affect other parts of a program Professor John Carelli Kutztown University Source: Pearson Education, Inc.
Features of OOP - Polymorphism • Behavior depends on usage • Functions can be “overloaded” • Different behavior for different argument lists • Different behavior for different argument types or sub-types • Ex: General/polym. cpp • addition (‘+’ operator) using int’s, float’s, and even strings • Functions can be made type-independent • via “templates” Professor John Carelli Kutztown University Source: Pearson Education, Inc.
Features of OOP - Inheritance • Objects can be based on another object • • “group” properties are inherited Existing properties can be modified New properties can be added Hierarchical int num. Legs= 4; Mammal bool warn. Blooded= true; Animal • Example: bool alive= true; • Animals -> Mammals -> Dogs Professor John Carelli Dog Kutztown University Source: Pearson Education, Inc.
- Slides: 7