Your SlideShare is downloading. ×
Lecture01
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Lecture01

901
views

Published on

Object Oriented Concepts …

Object Oriented Concepts
Object Oriented Programming (OOP) vs. Structured/Procedural Programming


0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
901
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
36
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Object Oriented Software Modeling and Design CE 350 Abdel-Karim Al-Tamimi, Ph.D. [email_address] http://faculty.yu.edu.jo/altamimi Al-Tamimi 2010 ©
  • 2. Overview
    • Object Oriented Concepts
    • Object Oriented Programming (OOP) vs. Structured/Procedural Programming
    Al-Tamimi 2010 ©
  • 3. Introduction to OOP
    • Things in real life are objects , and an object has both: attributes and behaviors associated with it
    • Adam is a member of class Person , as a member of this class it takes on Person attributes and behaviors
    Walking, Eating, Sleeping, … Eye-Color, Age, Height, … Attributes Behaviors
  • 4. OOP Concepts
    • An object may have only attributes
      • Multiple attributes: struct
      • A single attribute (e.g. integer)
    • Attributes = data
    • Behavior = functions
    • Restricting the access to object’s data or functions is called data hiding
    • Combining data and behavior in the same object is called encapsulation
  • 5. OOP vs. Procedural Programming Inputs Outputs object OOP Global Data Procedural Function 1 Function 2 Function 4 Function 3
  • 6. Moving from Procedural to OOP
    • Procedural separates data from the data-manipulations done on it
    • OOP encapsulates both data and its manipulation inside one object
  • 7. Procedural/Structured Programming
    • Carry out the required tasks using functions, if the function is too big, break it down to smaller functions
      • Functional decomposition
    • Functions are correlated with each other to form a data flow diagram (DFD)
    Input Process Output
  • 8. Structured Programming Students Exams Courses Tutors Add Student Enter for Exams Check Exam Marks Issue Certificate Expel Student
  • 9. Structured Programming
    • Harder to maintain as the system grows
    • The impact of one change can affect many functions, which are hard to trace and to re-test
    • To overcome these difficulties in maintaining the code and to perform expected adjustments, object oriented approach was introduced
  • 10. How to Think in Terms of Objects
    • Know the difference between interface and implementation
    • Think more abstractly
    • Give the user the minimal interface possible
  • 11. Object to Object Communications MyObject AnotherObject Data Data MyFunction1 MyFunction2 Function_1 Function_2
  • 12. Object to Object Communications
    • Each object provide a specific interface to allow other objects to communicate with it
    • The class interface includes the following:
      • The method/function name
      • The inputs passed to the method/function
      • The return type of the method/function
    • Any public data is considered also as a part of the class interface(better use get/set methods)
    • By designing the class interfaces , the developer hide extra or sensitive data
  • 13. Object to Object Communications
  • 14. Interface vs. Implementation
  • 15. Interface vs. Implementation
    • Only the services the end user needs are represented
      • Data hiding with the use of encapsulation
    • Change in the class implementation should not require change in the class user’s code
      • Interface is still the same
    • Always provide the minimal interface
    • Use abstract thinking in designing interfaces
      • No unnecessary steps
      • Implement the steps in the class implementation
  • 16. Interface vs. Implementation Student Age, GPA, … +getAge():integer +admit():void +expel():void +getFullName():string attributes methods
  • 17. How to determine the minimum interface possible
    • Only what the user absolutely needs
      • Fewer interfaces as possible
      • Use polymorphism
    • Starts with hiding everything (private)
      • Only use public interfaces (try not to use public attributes, instead get/set)
    • Design your class from the user’s perspective and what they need (meet the requirements)
  • 18. Determining the Class’s Environment
    • Determine the class user
      • What type of technical programmer
    • Determine the behavior of the object
    • Environmental constraints on objects
      • Hardware or/and software constraints
    • The next step is the implementation, anything that is not a public interface is considered an implementation
  • 19. Concept of Scope
    • Local attributes
      • Local to a specific method
    • Object attributes
      • Attributes shared between object methods
    • Class attributes
      • Attributes share between objects
      • Starts with static identifier
    public class Employee{ … static int Count; … }
  • 20. Object Attributes vs. Class Attributes
  • 21. Inheritance
    • Inheritance allows reusing code, with a better organization and overall management
    • Inheritance allows classes to inherit attributes from other classes, and you can still overwrite common behaviors
    • Inheritance categorizes classes into superclasses (parent class) and subclasses (child class)
  • 22. Inheritance
  • 23. Multiple Inheritance
    • Class can inherit multiple classes
    • In real life: kids inherit both father and mother attributes and behaviors
    • Multiple inheritance is a complex solution that can solve complex problems elegantly
      • Problem to the designer
      • Problem to the programming language compiler writer
      • Java and C# decided not to allow it in the form C++ allows it
    • C# uses interfaces to carry on the architecture of methods that a child class should have
  • 24. Polymorphism
    • Polymorphism means many shapes
    • Polymorphism allows a single behavior to have different interfaces, and thus different inner-object behavior
    • Polymorphism means that similar objects can respond to the same message in different manners
    • Polymorphism gives the developer more options and different levels of customization to achieve a certain data manipulation or output
  • 25. Polymorphism Al-Tamimi 2010 © +ReturnArea():double Shape +ReturnArea():double Circle +ReturnArea():double Square Area = Length^2 Area =   Radius^2 Returns a double value
  • 26. Polymorphism Al-Tamimi 2010 © +GetArea(Shape) MainClass Will call Shape.ReturnArea() Area = Length^2 Area =   Radius^2 If shape is Circle If shape is Square
  • 27. Constructors
    • Only with objects
    • No return value (even void)
    • Method name is identical to class name
    public Student(int StudentNumber) { /* Implementation Code */ } ... Student BestStudent = new Student(1234); ...
  • 28. Constructors
    • Default constructor (no arguments)
    • Any object will have a constructor even if you do not define it, since it inherits its superclass constructor
      • Every object is a subclass of object class
      • Superclass constructor is called by default
    • Always provide a constructor
    • Overloading methods/constructors
      • Same method name, different parameters
      • Polymorphism : using different objects that have the same superclass (child override parent)
  • 29. Constructors
    • Initialize all attributes
    • Make sure that the initialization values leaves the object in a stable and safe state
    • Do not include implementation in the constructor
      • Call a method if needed
    Student Age, GPA, … +Student: +getAge:integer +admit:void +expel:void +getFullName:string
  • 30. Error Handling
    • What can be done as a software developer when there is a potential risk of causing an error:
      • Ignore the problem that might cause the error
        • Very dangerous, even if it has a very low probability
      • Check the problem then abort the program
        • Handle the error by aborting the program, and show the error message
      • Check the problem, and try to fix it
        • You already know how to fix it, may not be the best solution
      • Check the problem and throw an exception
        • Throw the exception to the calling object to handle it
  • 31. Exception Handling
    • Exception is unexpected event that happens in the system
    • We use keywords : try and catch and throw to manage exceptions
    try { // potential risky code } catch( Exception object) { // how to solve the exception // can not solve it, throw an exception }
  • 32. Composition
    • Composition is to combine multiple objects to achieve a better or more complex objects
    • Example : A computer is composed of different objects : memory, hard drive, motherboard, and each of these objects are composed of smaller objects … etc
  • 33. Resources
    • Matt Weisfeld, The Object Oriented Thought Process , Sams Publishing, ISBN:0-672-32611-6