Presentation is loading. Please wait.

Presentation is loading. Please wait.

Instructor: Tasneem Darwish1 University of Palestine Faculty of Applied Engineering and Urban Planning Software Engineering Department Object Oriented.

Similar presentations


Presentation on theme: "Instructor: Tasneem Darwish1 University of Palestine Faculty of Applied Engineering and Urban Planning Software Engineering Department Object Oriented."— Presentation transcript:

1 Instructor: Tasneem Darwish1 University of Palestine Faculty of Applied Engineering and Urban Planning Software Engineering Department Object Oriented Analysis & Design Object Concepts part2

2 Instructor: Tasneem Darwish2 Links and navigability  connections that you’ve seen on object diagrams until now are called links  If we want to show that one object knows where the other one is, we can add an arrowhead

3 Instructor: Tasneem Darwish3 Links and navigability  Each link can be thought of as an attribute  the label, or role, indicates the attribute’s name  aCustomer has an attribute, called address, that links it to an Address object, and another attribute, called name, that links it to the String representing its name.

4 Instructor: Tasneem Darwish4 Links and navigability  The arrowhead indicates navigability, knowing where the other object is.  Because there’s no arrowhead on the customer end, the String doesn’t know that it’s associated with aCustomer.  Navigable links often end up as pointers in object-oriented programs

5 Instructor: Tasneem Darwish5 Links and navigability  One of the advantages of an object diagram is that it allows us to show what’s going on in our model at an arbitrary level of detail.  The naming convention used for objects, attributes and roles is: 1. use one or two descriptive words and run them together, 2.capitalize each word after the first.

6 Instructor: Tasneem Darwish6 Links and navigability  The key in all diagrams is to show as much detail as needed to achieve our goal.  Don’t let anyone suggest that a diagram is wrong just because they would have drawn it differently.

7 Instructor: Tasneem Darwish7 Messages  Every object is connected to at least one other object.  Connected objects can collaborate to perform more complex tasks.  Objects collaborate by sending messages to each other  the figure is a UML communication diagram.  Communication diagrams look rather like object diagrams, except that the links have no direction and the object names are not underlined.

8 Instructor: Tasneem Darwish8 Messages  Ideally, there should be sequence numbers, but they’ve been omitted here.  The receiving object may or may not need to provide a reply: we would expect replies to ‘What’s the time?’ and ‘What is your name?’, but not to ‘Start the engine’

9 Instructor: Tasneem Darwish9 Messages  when an object receives a message, it must carry out the request and no request is refused.  some requests can’t be carried out and the request fail

10 Instructor: Tasneem Darwish10 Invoking an Operation  When a software object receives a message, it executes some code called an operation. (a message invokes an operation)  In UML, we can show a message being sent from the sender to the receiver, or we can show the operation on the receiver, or we can do both.  messages can have parameters (also called arguments).  A parameter is an object or a simple value that the receiver needs in order to fulfil the request.  for example, send the message ‘What is your height in meters’ for a person object getHeight(meters)

11 Instructor: Tasneem Darwish11 Invoking an Operation  A good guideline for message styles, one that helps us to avoid many difficulties, is ‘A message should be a question or a command, but not both’.  A question message asks the object for some information, so it always has a reply.  A command message tells an object to do something and the object doesn’t need to provide a reply  A command alters the receiving object or some object that it’s connected to.

12 Instructor: Tasneem Darwish12 En example of collaboration  A customer walks into a baker’s shop and asks the baker what kind of loaves she has for sale. The baker looks under the counter and tells the customer that she has two white loaves and one wholemeal loaf. The customer says that he would like to buy the wholemeal loaf. Now the business transaction takes place: the baker wraps the loaf and offers it up with a request for payment; the customer gives the baker some money; the baker gives the customer some change. The customer leaves, satisfied.

13 Instructor: Tasneem Darwish13 En example of collaboration

14 Instructor: Tasneem Darwish14 How an object oriented program works  An object-oriented program works by creating objects, connecting them together and getting them to collaborate by sending messages to each other.  But Who creates the first object and who sends the first message?  To solve this problem, all object oriented programs have an entry point.  For example, Java expects to find an operation called main.  All the instructions in the main operation are executed, one after the other, and the program stops when main has finished.

15 Instructor: Tasneem Darwish15 Garbage collection  each new object occupies a small area of the computer’s memory;  as the program runs, it tends to create more and more objects, reducing the memory available to run other programs.  If we didn’t reclaim objects after we had finished with them, our computer might run out of memory unnecessarily.

16 Instructor: Tasneem Darwish16 Garbage collection  Traditionally, programmers have to decide when the last connection to an object was about to be removed so that they could explicitly delete or free the object’s  Languages such as Java have popularized the idea of a program that reclaims its objects automatically, without the programmer having to do anything.  every program has an assistant called a garbage collector

17 Instructor: Tasneem Darwish17 Classes  A class encapsulates characteristics common to a group of objects.  In UML, classes are drawn as boxes on a class diagram  class names (on class diagrams) are not underlined  Classes and objects are rarely mixed on the same diagram  Every object is an instance of a class.  class names start with a capital letter

18 Instructor: Tasneem Darwish18 Classes  Classification – grouping things into classes – is something that humans are rather good at.  classification is the core of object oriented thinking.

19 Instructor: Tasneem Darwish19 Classes  The figure shows the UML representation of the classes.  a white arrow-head is used to point from each detailed concept to the less detailed one on its left

20 Instructor: Tasneem Darwish20 Classes  There are a few common names for this kind of hierarchy: Inheritance: Trains inherit the characteristics of land vehicles. Generalization/specialization: A train is more specialized than a land vehicle; a land vehicle is more generalized than a train. Parent/child: LandVehicle is the parent of Train; Train is a child of LandVehicle. Superclass/subclass: LandVehicle is the superclass of Train; Train is a subclass of LandVehicle. Base/derived: LandVehicle is the base from which Train is derived.

21 Instructor: Tasneem Darwish21 What does a class define?  Object-oriented developers use classes to describe the programming elements that particular kinds of object will have.  Without classes, we would have to add these elements to every individual object.

22 Instructor: Tasneem Darwish22 What does a class define?

23 Instructor: Tasneem Darwish23 What does a class define?

24 Instructor: Tasneem Darwish24 Shared data and shared operation  object-oriented languages usually allow the programmer to put elements onto the class itself.  Java programmers, for example, can use the keyword static to indicate that an element is associated with the whole class rather than any of its instances.  Class elements are not as easy to use as they could be  the following are alternative:  Use a Singleton, a class that is guaranteed, by careful programming, to have only one instance

25 Instructor: Tasneem Darwish25 Types  In the pure object-oriented universe, everything is an object.  most object-oriented languages also have nonobject types, called primitives.  Taking Java as an example, we can declare that a field has a class type such as String – a sequence of characters – or a primitive type such as int – a simple number  The main distinction between objects and primitives is that, you can’t send a message to a primitive  Most languages provide us with a handful of ready-made primitive types. For example, Java gives us byte, short, int, long, float, double, char and boolean

26 Instructor: Tasneem Darwish26 Terminology

27 Instructor: Tasneem Darwish27 Reusing code  reuse refers to using code more than once, resulting in: Faster and simpler development. Easier maintenance (less code to harbour faults). More robust code (every time it is reused, it is retested and, over time, more and more faults are squeezed out).

28 Instructor: Tasneem Darwish28 Reusing code  Reuse opportunities can be summarized into the categories listed below:  Reusing functions within a system  Reusing methods within an object  Reusing classes within a system  Reusing functions across systems  Reusing classes across systems  Reusing classes across all systems

29 Instructor: Tasneem Darwish29 How should you design for reuse?  Here are some tips: 1.follow style guidelines: Style guidelines may originate from your company 2.Be thorough with your documentation: (comments and class description) 3.Be prepared to write more code than you need 4.Use patterns and frameworks: (they are understood by other developers) 5.Design client–supplier objects 6.Make each object single-purpose 7.Separate the interface from the business behaviour 8.Design for questions or commands


Download ppt "Instructor: Tasneem Darwish1 University of Palestine Faculty of Applied Engineering and Urban Planning Software Engineering Department Object Oriented."

Similar presentations


Ads by Google