Object oriented programming


Published on

Object oriented programming

Published in: Education
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Object oriented programming

  1. 1. Disclaimer: This presentation is prepared by trainees of baabtra as a part ofmentoring program. This is not official document of baabtra – MentoringPartnerbaabtra – Mentoring Partner is the mentoring division of baabte System Technologies Pvt. Ltd
  2. 2. Object Oriented Programming (OOP) Arjun P Ajay
  3. 3. Pop-Procedure OrientedProgramming Language(Structuredprogramming)• Structured programming is based around data structures and subroutines• The subroutines are where stuff actually "happens"• data structures are simply containers for the information needed by those subroutines.
  4. 4. POP can be briefly summarized as• No code reusability. Hence time to develop the software and debugging increase.• As Length of application increases, the programmer loses control over it.
  5. 5. • software designers tend to use Top-Down approach, in which the overall objective of the system is defined first.• Then the system is divided into various sub tasks or sub modules.• With this methodology, software development is done by writing a set of sub programs, called functions that can be integrated together to form a complex system.
  6. 6. What is oop
  7. 7. What is oop OOP allow decomposition of program into a number of entities called objects . Build data and functions around these objects. Object consist of data and function. The data of an object can be accessed only by the functions associated with that object
  8. 8. What is OOP?• Objects can be used effectively to represent real-world entities• An object oriented program may be considered a collection interacting object.• Each object is capable of sending and receiving messages and processing data
  9. 9. Object oriented programmingconcepts• Object• Class• Data Abstraction• Modularity• Delegation• Encapsulation• Polymorphism• Inheritance
  10. 10. Class• A class is the blueprint of an object• Multiple objects can be created from the same class• Class is a collection of member data and member functions.• Objects contain data and code to manipulate that data.• The entire set of data and code of an object can be made a user-defined data type with the help of a class.
  11. 11. Class members• Namespace: The namespace is a keyword that defines a distinctive name or last name for the class.• Class declaration: Line of code where the class name and type are defined.• Fields: Set of variables declared in a class block.• Constants: Set of constants declared in a class block.• Constructors: A method or group of methods that contains code to initialize the class.
  12. 12. • Properties: The set of descriptive data of an object.• Events: Program responses that get fired after a user or application action.• Methods: Set of functions of the class.• Destructor: A method that is called when the class is destroyed
  13. 13. Access keywords• Access keywords define the access to class members from the same class and from other classes• Public: Access to the class member from any other class. Accessible from outside of the class & assembly– It can access from anywhere– There is no restriction on accessibility• Private: Access to the class member only in the same class.• Protected: Allows access to the class member only within the same class and from inherited classes. Accessible within class & sub-classes• Internal: Allows access to the class member only in the same assembly.• Protected internal: Allows access to the class member only within the same class, from inherited classes
  14. 14. Imported namespaces Imports System Namespace: Consider using CompanyName.Product.ComponentType Namespace DotNetTreats.OOSE.OOP_VBNETClass declaration Public Class employeeFieldsPrivate _name As StringPrivate _salary As IntegerConstantsPrivate Const anualBonus As Integer = 1000ConstructorsPublic Sub New()MyBase.New()End Sub
  15. 15. PropertiesPublic Property Name() As StringGetReturn _nameEnd GetSet(ByVal Value As String)_name = valueEnd SetEnd PropertyPublic Property Salary() As IntegerGetReturn _salaryEnd GetSet(ByVal Value As Integer)_salary = valueEnd SetEnd Property
  16. 16. Event handlersPublic Event OnPromotion As EventHandlerMethodsPublic Sub DuplicateSalary()_salary = (_salary * 2)End SubEnd ClassEnd NamespaceByVal is short for "By Value"*it means is that you are passing a copy of a variable to your Subroutine.* You can make changes to the copy and the original will not be altered.ByRef short for By Reference*you are not handing over a copy of the original variable but pointing to the original variable.
  17. 17. Objects An object is anything that really exists in the world and can be distinguished from othersEvery object has properties andcan perform certain actionsThese properties are representedby variables in programming andactions are performed by methods(functions). So an object containsvariables and methods Objects are the building blocks of OOP and are commonly defined as variables or data structures
  18. 18. Object composition• Object identity: Means that every object is unique and can be differentiated from other objects. Each time and object is created (instantiated) the object identity is defined.• Object behavior: What the object can do. In OOP, methods work as functions that define the set of actions that the object can do.• Object state: The data stored within the object at any given moment. In OOP, fields, constants, and properties define the state of an object.
  19. 19. Structures Not everything in the real world should be represented as a class.• Structures are suitable to represent lightweight objects.• Structures can have methods and properties and are useful for• defining types that act as user-defined primitive
  20. 20. Encapsulation• The wrapping up of data and functions into a single unit (called class) is known as encapsulation.• In OOP we are capsuling our code not in a shell but in "Objects" & "Classes".• It hides all the internal details of an object from the outside world• It hides its data and methods from outside the world and only expose data and methods that are required.• It provides us maintainability, flexibility and extensibility to our code.• Encapsulation allows developers to build objects that can be changed without affecting the client code that uses them
  21. 21. • The data is not accessible to the outside world and only those functions which are wrapped in the class can access it.• These functions provide the interface between the objects data and the program.• This insulation of the data from direct access by the program is called data hiding.
  22. 22. Data Abstraction• “The process of identifying common patterns that have systematic variations; an abstraction represents the common pattern and provides a means for specifying which variation to use"• An abstract class is a parent class that allows inheritance but can never be instantiated• Abstract classes contain one or more abstract methods that do not have implementation.• Abstract classes allow specialization of inherited classes.
  23. 23. Data Abstraction contn…• Abstraction is a powerful means to tackle the complexity of programming by wrapping up and thus reducing the complexity of complex operations.• In this it display only the features that needed the user, and hide all other data• Through Abstraction all relevant data can be hide in order to reduce complexity and increase efficiency
  24. 24. Polymorphism• Its the property in which a single object can take more than one form.• Single interface & multiple method is called polymorphism.• Polymorphism allows objects to be represented in multiple forms.• Polymorphism is a concept linked to inheritance and assures that derived class have the same function even though each derived class performs different operationsEx:• Function overloading (Static polymorphism / early binding).• Function overriding (dynamic polymorphism / late binding).• Polymorphism allows a client to treat different objects in the same way even if they were created from different classes and exhibit different behaviors.
  25. 25. Polymorphism• Method Overloading- Method with same name but with different arguments is called method overloading.- Method Overloading forms compile-time polymorphism.• Method Overriding- Method overriding occurs when child class declares a method that has the same type arguments as a method declared by one of its super class.- Method overriding forms Run-time polymorphism.
  26. 26. • Modularity-The modularity of object-oriented programming means that the valid components of a big program can each be implemented individually.-Different people can work on various classes.-Each execution task is isolated from the others.-A ``module is nothing more than a file containing source code. - Breaking a large (or even not-so-large) program into different files is a convenient way of splitting it into manageable pieces. -Each piece can be worked on independently and compiled alone, then integrated with other pieces when the program is linked
  27. 27. Delegation Delegation allows the behavior of an object to be defined in terms of the behavior of another object. ie , Delegation is alternative to class inheritance.• Delegation is a way of making object composition as powerful as inheritance.• In delegation, two objects are involved in handling a request: -A receiving object delegates operations to its delegate. -This is analogous to the child classes sending requests to the parent classes.
  28. 28. • When an object receives a request, the object can either handle the request itself or pass the request on to a second object to do the work.• If the object decides to pass the request on, you say that the object has forwarded responsibility for handling the request to the second object.
  29. 29. Inheritance• Inheritance is the property in which, a derived class acquires the attributes of its base class.• you can create or inherit your own class (derived class), using an existing class (base class). You can use the Inherits keyword for this.• In OOP, a parent class can inherit its behavior and state to children classes.• This concept was developed to manage generalization and specialization in OOP and is represented by a is-a relationship.
  30. 30. *The concept of generalization in OOP means that an objectencapsulates common state an behavior for a category ofobjects.*The general object in this sample is the geometric shape.*Most geometric shapes have area, perimeter, and color.*The concept of specialization in OOP means that an objectcan inherit the common state and behavior of a genericobject;however, each object needs to define its own special andparticular state an behavior
  31. 31. The Shape class is theparent class.Square, Rectangle, andCircle are derivedclasses that inheritfrom Shape. Thetriangle-connector inthe diagram representsan is-a relationship.
  32. 32. Imports SystemClass HumanThis is something that all humans do Public Sub Walk() Console.Writeline ("Walking") End Sub End Class‘A Programmer is a HumanClass ProgrammerInherits Human We already have the above Walk() functionThis is something that all programmers do ;)Public Sub StealCode()Console.Writeline ("Stealing code")End SubEnd Class
  33. 33. • Example Program for classPublic Class ExamplePrivate _value As Integer Public Sub New() _value = 2 End Sub Public Function Value() As Integer Return _value * 2 End FunctionEnd ClassModule Module1 Sub Main() Dim x As Example = New Example() Console.WriteLine (x.Value()) End SubEnd Module -----------(out put =4)
  34. 34. • Program that uses Inherits keyword [VB.NET]Class A Public _value As Integer Public Sub Display() Console.WriteLine(_value) End SubEnd ClassClass B : Inherits A Public Sub New(ByVal value As Integer) MyBase._value = value End SubEnd ClassClass C : Inherits A Public Sub New(ByVal value As Integer) MyBase._value = value * 2 End SubEnd Class
  35. 35. Module Module1 Sub Main() Dim b As B = New B(5) b.Display() Dim c As C = New C(5) c.Display() End SubEnd Module
  36. 36. • Imports Systempublic Class Circle Public Radius As Double Public Function CalculateDiameter() As Double Return Radius * 2 End Function Public Function CalculateCircmuference() As Double Return CalculateDiameter() * 3.14159 End Function Public Function CalculateArea() As Double Return Radius * Radius * 3.14159 End FunctionEnd Class
  37. 37. Public Class Exercise Public Sub Main() Dim circ As Circle = New Circle circ.Radius = 25.84 Console.WriteLine(" -=- Circle Characteristics -=-") Console.WriteLine("Radius: {0} ", circ.Radius) Console.WriteLine("Diameter:{0} ",circ.CalculateDiameter()) Console.WriteLine("Circumference:{0} ", circ.CalculateCircmuference()) Console.WriteLine("Area: {0} " & vbCrLf, circ.CalculateArea()) End SubEnd Class
  38. 38. • Result• -=- Circle Characteristics -=-Radius : 25.55Diameter : 51.1Circumference: 160.535249Area : 2050.837805975
  39. 39. • Advantages of OOP Object-Oriented Programming has the following advantages over conventional approaches:• OOP provides a clear modular structure for programs which makes it good for defining abstract data types where implementation details are hidden and the unit has a clearly defined interface.• OOP makes it easy to maintain and modify existing code as new objects can be created with small differences to existing ones.• OOP provides a good framework for code libraries where supplied software components can be easily adapted and modified by the programmer. This is particularly useful for developing graphical user interfaces.
  40. 40. Thank You
  41. 41. Contact Us