Overview of OOPs Object Oriented Programming Structure Concepts
Overview of OOPs (Object Oriented Programming Structure) Concepts
OOP Paradigm • Programming paradigm - Way of thinking / approaching a problem • Style of computer programming, serving as a way of building the structure and elements of computer programs. • Influences the programming language and other things built on top of the language, such as libraries, frameworks, and common styles and patterns of programming.
OOP Paradigm • Way of looking at something. • When TV came out it was a new paradigm; everything changed • Twitter is a new paradigm in communication • When the Internet took off, it was a new paradigm, and now we have Online Shopping for Electronics, Apparel, Computers, Books, DVDs & more
OOP Paradigm • Programming paradigm - Way of thinking / approaching a problem • Style of computer programming, serving as a way of building the structure and elements of computer programs. • Influences the programming language and other things built on top of the language, such as libraries, frameworks, and common styles and patterns of programming.
Types of Programming Paradigm • Imperative programming paradigm • Functional programming paradigm • Logic programming paradigm • Structural programming paradigm • Object-oriented programming paradigm Different paradigms permit and forbid certain techniques.
Multi – Paradigm Language • Language that supports more than one paradigm • C++ is one such language • Supports Procedural/Object Oriented Programming
Popular OO Languages—A glance • • C++ Java Smalltalk Charm++ Simula Ada Eiffel
Advantages of Object Oriented Programming • Improved software-development productivity – Consider the entire life cycle of a person to understand – Modular (He learn lessons, play, watch TV, prepare food etc) – Extensible - objects can be extended to include new attributes and behavior (A baby has name, father name, mother name, when joined school has admission number class of studying, when joined job has employee id, salary etc. Funationalitites that can be performed also increases)
Advantages of Object Oriented Programming – reused within and across applications – Same person is a employee of an organization, mother/ father at home, son / daughter to their parents – Sometimes a person does a job for his family / friends • Improved software maintainability: Since the design is modular, part of the system can be updated in case of issues without a need to make large-scale changes
Advantages of Object Oriented Programming • Faster development: Reuse enables faster development. Object-oriented programming languages come with rich libraries of objects • Lower cost of development: reuse of software also lowers the cost • Higher-quality software: Faster development of software and lower cost of development allows more time and resources to be used in the verification of the software.
Disadvantages of Object Oriented Programming • Steep learning curve: The thought process involved in object-oriented programming may not be natural for some people, and it can take time to get used to it. • Larger program size: More lines of code than procedural programming • Slower programs: Object-oriented programs are slower than procedure based programs • Not suitable for all types of problems
Basis of Object Oriented Programming • View the problem world as a set of objects and communication between the objects • Entire world around as can be thought as a set of objects • Objects have characteristics and they can perform some functions • Similar objects may be grouped together
Human Body Parts In OOP Hand: • Characteristics: – Covered in skin = true. – number of bones = 42 (I have no idea how many a human hand really has) – number of fingers = 5. • Methods/Things it can do: – Grasp object – Count to five with fingers – Point index finger
Human Body Parts In OOP Heart: • Characteristics: – Pumps blood = true – Internal Organ = true – Covered in skin = false • Methods/Things it can do: – Speed up pumping. – Slow down pumping.
Features of Object Oriented Paradigm
Case Study: OOP Design for Railway Reservation System • Identify the Objects involved in the process
Railway Reservation System • Train • Coaches / Compartments • Station • Passenger • Employee of railways • Route • Ticket • Distance matrix
What is UML? UML stands for “Unified Modeling Language” • It is a industry-standard graphical language for specifying, visualizing, constructing, and documenting the artifacts of software systems • The UML uses mostly graphical notations to express the OO analysis and design of software projects. • Simplifies the complex process of software design
Why UML for Modeling • Graphical notation to communicate more clearly • Help acquire an overall view of a system. • UML is not dependent on any one language or technology. • UML moves us from fragmentation to standardization.
Encapsulation • Binds together the data and functions that manipulate the data, and that keeps both safe from outside interference and misuse • Classes are in C++ to encapsulate • C with Classes - Name given by Stroustrup • Classes are extension of structures with functions as members • In C++, structures can also have functions
Class is generalization of objects where data and functions are grouped
Class • Depicts the set of similar objects as mentioned in the previous example. • It distinguishes one type of object from another type • A Class is an User defined data type • A class comprised of attributes and functions. • Attributes defines the properties of the object and function describes “What an object is capable of doing” • The class is like a blue print of a house and it indicates how the data and functions are used by the objects.
Objects • In programming perspective, instance of a class
Classes and Objects in Railway Reservation System Classes Train Coaches/Compartment Station Passenger Employee of railways Route (Stations through which train travel) Ticket Distance matrix Objects Tamilnadu SF Express B 1 Chennai Central Any person travelling in train Travelling Ticket examine. R (TTR) Chennai Central (Terminus), Vijayawada, Warangal. . . New Delhi Ticket possessed by a passenger Distance between stations of Indian railways
Class diagram in UML • Used for describing structure and behavior in the use cases • Provide a conceptual model of the system in terms of entities and their relationships • Used for requirement capture, end-user interaction • Detailed class diagrams are used for developers
Class diagram in UML • Each class is represented by a rectangle subdivided into three compartments – Name – Attributes – Operations
Data Abstraction • Providing only essential information to the outside world and hiding their background details • By abstraction, a programmer hides all but the relevant data about an object in order to reduce complexity and increase efficiency • Stepping away from a complex or unsafe algorithm by black boxing it and always using that black box • Makes code to be manageable
Data Abstraction • Access Labels Enforce Abstraction: • Three Access labels in C++ – Private – Public – Protected
Data Abstraction in UML • Modifiers are used to indicate visibility of attributes and operations. – ‘+’ is used to denote Public visibility (everyone) – ‘#’ is used to denote Protected visibility (friends and derived) – ‘-’ is used to denote Private visibility (no one) • By default, attributes are hidden and operations are visible.
Other UMLs diagarams shall also be referred
Data Abstraction
Abstraction in Railway Reservation System Classes Train Coaches/Compartment Station Passenger Employee of railways Route (Stations through which train travel) Ticket Distance matrix Information Hidden Date of manufacturing for engine Cleanliness, Painted color, Length of the stations, shops Number of children Employee id, Salary Number of tracks Printed, mobile ticket Quality of track
- Slides: 36