Object Oriented Software Development by elfphabet3


									Object Oriented Software Development

         Vrije Universiteit Brussel
             Jonckers Viviane
Material For This Course

 Handouts of transparencies (on-line)

 Timothy Budd, An Introduction to Object Oriented Programming, third
   edition, Addison Wesley, 2002
 Martin Fowler, UML Distilled, third edition, Addison Wesley , 2004

 Gamma, Helm, Johnson, Vlissides, Design Patterns, Addison Wesley,
 A C++ or JAVA handbook

22-Dec-09                     Jonckers Viviane                          2
 Practical Information

 Website
   –   Transparencies
   –   Exercise Assignments
   –   Exercise Solution
   –   Extra exercises and solutions (for those who want to practice more )
   –   DP assignment

  http://ssel.vub.ac.be  Courses  Object Oriented Software
  Development (OOSD)

 22-Dec-09                      Jonckers Viviane                          3
Object Oriented Software Development

 Broad View: object oriented programming is about object
  oriented software development technology in the large
 Narrow View: object oriented programming is about using an
  object oriented programming language for implementing
    – Practical Option: A class on a typical object oriented programming
      language such as C++ or JAVA or Smalltalk or CLOS or …
    – Conceptual Option: A class on the concepts of object oriented
      programming illustrated by fragments of C++ and/or JAVA and/or

22-Dec-09                     Jonckers Viviane                             4
Object Oriented Software Development

 Evolution View: object oriented programming is an
   evolutionary step following naturally on the heels of earlier
   programming abstractions - development technologies

 Revolution View: object oriented programming is a
   revolutionary idea, a paradigm shift from previous
   programming techniques - development methodologies

22-Dec-09                   Jonckers Viviane                       5
OOSD Narrow View

 Classes & Objects
 Messages & Methods
 Class Hierarchies & Inheritance
 Encapsulation & Information Hiding
 Method Binding & Polymorphism

22-Dec-09             Jonckers Viviane   6
OOSD Broad View

 Object Oriented                 Reuse
   Analysis and Design
   with UML                       Design Patterns
    – Use Cases
    – Class Diagrams              Components
    – Interaction Diagrams
    – Activity Diagrams
                                  Frameworks
    – State Diagrams
22-Dec-09              Jonckers Viviane              7
Why is OOSD Popular?

 Resonant similarity to techniques of thinking about
   problems in real life and in other domains
 Scales very well from trivial problems to complex
 Libraries support application development in many
22-Dec-09               Jonckers Viviane                8
Programming Language
and Problem Solution
Example: analysis of DNA sequence

 DNA sequence is represented as a vector of integer
 Find whether any pattern of length M (M fixed and
  small) is repeated in a given DNA sequence of length
  N (N very very large)

22-Dec-09             Jonckers Viviane                 9
The Fortran Solution

DO 10 I = 1, N-M
DO 10 J = 1, N-M
DO 20 K = 1, M
   IF X[I+K-1] .NE. X[J+K-1] THEN FOUND = .FALSE.

22-Dec-09              Jonckers Viviane             10
The APL Solution

Reorganise in matrix N x M Sort matrix on rows   Look for equal
ACTCCTC 1-7                ACTCCTC               adjacent rows
CTCCTCG 2-8                CCTCGAT
TCCTCGA 3-9                CGATCCA
CCTCGAT 4-10               CTCCTCG
CTCGATC 5-11               CTCGATC
TCGATCC 6-12               TCCTCGA
CGATCCA 7-13               TCGATCC

22-Dec-09                 Jonckers Viviane                    11
Comparison of Both Solutions

 Fortran programmer thinks in terms of loops
 Fortran solution was extremely slow O(M x N2)

 APL programmer thinks in terms of manipulating
  sequences; sort is built-in, loops do not exist
 APL solution is faster O(M x NlogN) although APL is
  not a “more efficient” language than Fortran
22-Dec-09             Jonckers Viviane                  12
Church’s Conjecture
and the Sapir-Worf Hypothesis
 Sapir-Worf Hypothesis: a much debated linguistic theory;
  asserts that an individual using a particular language may
  have thoughts and ideas that cannot be translated to or even
  be understood by an individual using a different language
 Church’s Conjecture: any computation for which there exists
  an effective procedure can be realised by a Turing Machine
 Avoid the “Turing Tarpit”: a new programming language may
  not provide a new computational power but it may be easier
  and more natural to address some problems in it
22-Dec-09                 Jonckers Viviane                   13
Object Oriented Solutions and
Object Oriented Programming Languages
 Effective use of object-oriented principles requires
  one to view the world in a new way
 The use of an object oriented language will simplify
  the development of object oriented solutions
 The use of an object oriented language does not
  make one an object oriented programmer
   “Fortran programs can be written in any language”

22-Dec-09              Jonckers Viviane                  14
A new paradigm?

 Paradigm = set of theories, standards and methods that
  together represent a way to organise knowledge and view
  the world
 In science a revolution occurs when an older paradigm is
  reexamined, rejected and replaced by another
 Programming paradigm = a way of conceptualising what it
  means to perform computation and how tasks to be carried
  out by a computer should be structured and organised

22-Dec-09                Jonckers Viviane                    15
OOSD : A Way of Viewing the World

“ Chris wants to send some flowers to his friend Robin
  who lives in a distant city. Because of the distance,
  Chris cannot pick up the flowers and bring them to
  Robin in person. Chris goes down to Fred a local
  florist and tells him the number and type of flowers
  he wants together with the address they need to be
  delivered to. Chris can rest assure that the flowers
  will be delivered. ”
22-Dec-09              Jonckers Viviane               16
Agents, Responsibility, Messages &Methods

 Chris finds an appropriate agent (Fred)
 And passes to him a message containing a request
 It is the responsibility of Fred to satisfy the request
 There is some method -a set of operations or algorithm-
  used by Fred to do this
 Chris does not need to know the particular method that Fred
  will use, this information is hidden from inspection

22-Dec-09                 Jonckers Viviane                  17
OOSD : The General Principle

 An object oriented program is structured as a community of interacting
  agents called objects. Each object has a role to play. Each object
  provides a service or performs an action that is used by other
  members of the community.
 Action is initiated in object oriented programming by the transmission
  of a message to an agent (an object). The message encodes the
  request for action and is accompanied by additional information
  (arguments) needed to carry out the request. The receiver is the agent
  to which the message is sent. If the receiver accepts the message it
  accepts the responsibility to carry out the indicated action. In response
  to a message the receiver will perform some method to satisfy the
22-Dec-09                      Jonckers Viviane                          18
Method Binding, Polymorphism and
Information Hiding
 When Fred would ask his wife Beth to send some flowers to Robin for
  her birthday she might use a different method than the florist Fred.
  (When Fred would ask his dentist to send some flowers there could be
  some confusion)
 The method that gets executed in response to a message depends on
  the receiver of the message. Getting different methods executes in
  response to the same message is a form of polymorphism
 A receiver takes responsibility for responding to a message; the
  sender of the message need not know the details of the method used.
  This is a standard powerful form of abstraction referred to as
  information hiding

22-Dec-09                    Jonckers Viviane                        19
Sending Messages vs. Procedure Call

 A message has a designated receiver (some object)
 The interpretation of the message, I.e. the method used in
  response to the message is determined by the receiver and
  can vary amongst different receivers.
 Often the actual receiver of a message is not known until
  run-time. There is late or dynamic binding between the
  message and the code fragment (method) used to respond
  to the message

22-Dec-09                 Jonckers Viviane                     20
Responsibility & Abstraction

 Discussing a problem in terms of responsibilities increases the level of
  abstraction and permits greater independence between agents
 The entire collection of responsibilities associated with an object is
  often described by the term protocol
 A traditional program often operates by acting on data structures. An
  object-oriented program requests data structures (objects) to perform a
  service. "Ask not what to do to your data structures but ask what your
  data structures can do for you)

22-Dec-09                      Jonckers Viviane                         21
Classes and Instances

 Although Chris does not know Fred very he has a rough idea of the
  transactions that occur inside Fred’s shop. Chris is able to make
  certain assumptions based on previous experiences with florists. He
  expects that Fred, being an instance of the category florist, will match
  the pattern.
 All objects are instances of a class. The method invoked by an object
  to respond to a message is determined by the class of the receiver. All
  objects of the same class use the same method in response to the
  same message.

22-Dec-09                      Jonckers Viviane                          22
Class Hierarchies & Inheritance

 Chris has more information about Fred, not necessarily to do with Fred
  being a florist but with Fred being a shop keeper, a human, a mammal,
  an animal or a material object
 The principle that knowledge of a more general category is also
  applicable to a more specific category is called inheritance.
 Classes can be organised into a hierarchical inheritance structure. A
  child class (or subclass) will inherit attributes from a parent class
  (super class) higher up in the hierarchy. An abstract parent class in a
  class for which there are no direct instances, it is only introduced to
  group subclasses.

22-Dec-09                     Jonckers Viviane                         23
Categories surrounding Fred

   Material Object
                                        Florist   Fred

22-Dec-09                    Jonckers Viviane            24
A Material Objects Class Hierarchy

                                            Material Object

                         Animal                                         Plant

                       Mammal                                           Flower

       Dog               Human                 Platypus                 Tulip

       Sam   Shopkeeper Health Worker            Phylis        tulip1   tulip2   tulip 3

               Florist            Dentist

                Fred               Ken

22-Dec-09                                   Jonckers Viviane                               25
Method Binding and Overriding

 Phylis is a platypus and thus a mammal. Mammals give life birth but
  Phylis does not, she lays eggs. This is an exception to the general rule
 The search for a method to invoke in response to a given message
  starts with the class of the receiver. If no appropriate method is found,
  the search continues up the parent class chain until either a method is
  found or the until the parent class chain is exhausted.
 Information contained in a subclass can override information inherited
  from a parent class. When methods with the same name are available
  higher in the class hierarchy the method that executes is said to
  override the inherited behavior

22-Dec-09                      Jonckers Viviane                          26
OOP and Avoiding Infinite Regression

   “ Instead of a bit-grinding processor plundering data
   structures, we have a universe of well-behaved objects that
   courteously ask each other to carry out their various desires”
 At some point at least some objects need to perform some work
  instead of just passing on the request to others
 Blended languages (C++, CLOS) write methods in the base language
 Pure object oriented languages (Smalltalk, Java) have primitive or
  native operations

22-Dec-09                    Jonckers Viviane                      27
Coping with Complexity

 Complexity of programming projects is non-linear
   – Two programmers cannot do in one month what one programmer
     can do in 2 months
   – Adding more men/women to a project often lengthens, not
     shortens, the schedule
 Interconnectedness, the dependence of one portion of code
  on another portion, is responsible for this phenomena
 Abstraction mechanisms try to cope with this and object
  oriented techniques offer yet another step forward

22-Dec-09                  Jonckers Viviane                       28

 Abstraction mechanisms are techniques to deal with
  creating, understanding and managing complex systems
 Abstraction is the purposeful suppression or hiding of some
  details of a process or artifact in order to bring out more
  clearly other aspects, details or structures
 Through abstraction one builds a model of the actual system

22-Dec-09                Jonckers Viviane                   29
Abstraction layers in OOSD

 At the highest level a program is viewed as a community of
  cooperating objects. Each object in this community provides
  services that can be used by other members. At this highest
  level the important features to emphasise are the services
  provided by each object and the lines of cooperation and
  communication between them.
 The next level of abstraction allows a group of objects
  working together to be grouped in a unit (packages, name
  spaces, units) allowing some names to be exposed to the
  world outside the unit while others remain hidden inside the
22-Dec-09                 Jonckers Viviane                     30
Abstraction layers in OOSD

 The next two levels of abstraction deal with the interaction
   between 2 individual objects where one (the client) uses
   services from the other (the server)
    – The server advertises the services it can provide for the client as
      an interface, the client programs to this interface
    – The server provides a concrete implementation for its interface
 The last level of abstraction considers a single task in
   isolation I.e. which steps implement a single method

22-Dec-09                      Jonckers Viviane                             31
General Forms of Abstraction

                                         class hierachies    ADT

               Specialisation                               patterns
               “is a”                   service view
                                                            OO programs
                                                            recursive algorithms
 abstraction   division into parts       repetition         recursive data structures
               “has a”

                multiple views                               dictionaries

22-Dec-09                            Jonckers Viviane                                   32
Abstraction mechanisms in programming
 Procedures and Functions (function centered view)
   + information hiding for the detail of the behavior
   - no information hiding for the detail of the data
   - no encapsulation
 Modules and Packages (data centered view)
   + information hiding
   + encapsulation
   - instantiation not always supported
 Abstract Data Types
   + separates interface and implementation
22-Dec-09                 Jonckers Viviane               33
Abstraction mechanisms in OO programming
 Classes are as Abstract Data Types in a service-centered
 Message Passing and Method Binding bring polymorfism
  leading to more readable code
 Class Hierarchies and Inheritance bring code sharing which
  results in increased functionality and reduction of code size
 Inheritance and polymorphism together allow for tailoring
  shared code

22-Dec-09                  Jonckers Viviane                       34
Object Oriented Design

 Object oriented software development is NOT about the
  syntax of a programming language
 Object oriented software development is about a design
  technique driven by the determination and delegation of
 Responsibility implies non-interference, it cuts or reduces the
  links between objects that depend on implementation details
 Goes beyond information hiding and encapsulation when
  dealing with programming in the large

22-Dec-09                  Jonckers Viviane                    35
Programming in the Small versus
Programming in the Large
 Code developed by single           Software system developed
  programmer or very small            by a large team
  set of programmers                 No single individual is
 Every individual
                                      responsible for the entire
                                      project or understands all
  understands all aspects of          aspects of it
  the project                        Major effort is in the
 Major effort is the design          management of details and
  and development of                  the communication of
  algorithms dealing with the         information between
  problem at hand                     different portions of the
22-Dec-09                 Jonckers Viviane                     36

To top