OOSE Chapter 3
OOSE Chapter 3
Practical Software Development using UML and Java Chapter 3: Basing Software Development on Reusable Technology
Lethbridge/Laganire 2005
A vicious cycle
Developers tend not develop high quality reusable components, so there is often little to reuse To solve the problem, recognize that: This vicious cycle costs money Investment in reusable code is important Attention to quality of reusable components is essential So that potential reusers have confidence in them The quality of a software product is only as good as its lowest-quality reusable component Developing reusable components can often simplify design
Lethbridge/Laganire 2005
Lethbridge/Laganire 2005
Lethbridge/Laganire 2005
Object-oriented frameworks
In the object oriented paradigm, a framework is composed of a library of classes. The API is defined by the set of all public methods of these classes. Some of the classes will normally be abstract Example: A framework for payroll management A framework for frequent buyer clubs A framework for university registration A framework for e-commerce web sites
Lethbridge/Laganire 2005
Lethbridge/Laganire 2005
Types of frameworks
A horizontal framework provides general application facilities that a large number of applications can use A vertical framework (application framework) is more complete but still needs some slots to be filled to adapt it to specific application needs
Lethbridge/Laganire 2005
Lethbridge/Laganire 2005
10
11
Lethbridge/Laganire 2005
12
Lethbridge/Laganire 2005
13
14
Lethbridge/Laganire 2005
15
Activities of a server
1. Initializes itself 2. Starts listening for clients 3. Handles the following types of events originating from clients
1. accepts connections 2. responds to messages 3. handles client disconnection
Lethbridge/Laganire 2005
16
Activities of a client
1. 2. 3. 4. Initializes itself Initiates a connection Sends messages Handles the following types of events originating from the server
responds to messages handles server disconnection
1. 2.
5.
Lethbridge/Laganire 2005
17
Lethbridge/Laganire 2005
18
Lethbridge/Laganire 2005
19
Communications protocols
The messages the client sends to the server form a language. The server has to be programmed to understand that language. The messages the server sends to the client also form a language. The client has to be programmed to understand that language. When a client and server are communicating, they are in effect having a conversation using these two languages The two languages and the rules of the conversation, taken together, are called the protocol
Lethbridge/Laganire 2005
20
Lethbridge/Laganire 2005
21
Lethbridge/Laganire 2005
22
23
Lethbridge/Laganire 2005
24
Lethbridge/Laganire 2005
25
Lethbridge/Laganire 2005
26
Using OCSF
Software engineers using OCSF never modify its three classes They: Create subclasses of the abstract classes in the framework Call public methods that are provided by the framework Override certain slot and hook methods (explicitly designed to be overridden)
Lethbridge/Laganire 2005
27
Lethbridge/Laganire 2005
28
Lethbridge/Laganire 2005
29
Lethbridge/Laganire 2005
30
Using AbstractClient
Create a subclass of AbstractClient Implement handleMessageFromServer slot method Write code that: Creates an instance of the new subclass Calls openConnection Sends messages to the server using the sendToServer service method Implement the connectionClosed callback Implement the connectionException callback
Lethbridge/Laganire 2005
31
Internals of AbstractClient
Instance variables:
A Socket which keeps all the information about the connection to the server Two streams, an ObjectOutputStream and an ObjectInputStream A Thread that runs using AbstractClients run method Two variables storing the host and port of the server
Lethbridge/Laganire 2005
32
Lethbridge/Laganire 2005
33
Lethbridge/Laganire 2005
34
Lethbridge/Laganire 2005
35
Lethbridge/Laganire 2005
36
Lethbridge/Laganire 2005
37
Lethbridge/Laganire 2005
38
Lethbridge/Laganire 2005
39
The server
EchoServer is a subclass of AbstractServer The main method creates a new instance and starts it It listens for clients and handles connections until the server is stopped The three callback methods just print out a message to the user handleMessageFromClient, serverStarted and serverStopped The slot method handleMessageFromClient calls sendToAllClients This echoes any messages
Lethbridge/Laganire 2005
40
Lethbridge/Laganire 2005
41
The client
When the client program starts, it creates instances of two classes: ChatClient A subclass of AbstractClient Overrides handleMessageFromServer
- This calls the display method of the user interface
Accepts user input by calling accept in its run method Sends all user input to the ChatClient by calling its handleMessageFromClientUI
- This, in turn, calls sendToServer
Lethbridge/Laganire 2005
42
Lethbridge/Laganire 2005
43
Lethbridge/Laganire 2005
44
Compatibility not maintained Avoid obscure features Only re-use technology that others are also re-using
Lethbridge/Laganire 2005
45
Lethbridge/Laganire 2005
46
Lethbridge/Laganire 2005
47
Lethbridge/Laganire 2005
48