Вы находитесь на странице: 1из 10

CST438 Software Engineering Fall 2016 Final Exam

Name : Christopher Luntsford

Directions:
The exam is open book and there is no time limit. However make sure you
submit your document before end of day Tuesday Dec 13th.
Do your own work. Sign the honor pledge.

Honor Pledge: I have not given nor received unauthorized assistance in doing
this exam.

Christopher Luntsford
Sign or print your name here.

Problem Points Your Score


1 30
2 30
3 20
4 20
total 100

1
1. UML Class Sequence diagram

A UML sequence diagram is used to show the details of class collaborations.

Download the file finalExam_questino1_UML.zip that contains classes: Weather (the main
class), WeatherJason and FetchTask. Create an eclipse Java project and copy these classes
into the project. To compile and execute the program you need to have the gson.jar file (also in
the zip) in your build path.

The user enters one or more names of cities separated by commas

An asynchronous background task is created to get the weather information from the web site
openweathermap.org and display it in a not too interesting text format (weather.com has nothing
to worry about here).

Complete the UML sequence diagram to show the interactions among the objects:
Weather.ActionListener, FetchTask,the UI components and the openweathermap.org web site.

In particular, show the creation of the FetchTask object, how does control pass to it, when does
control return to the UI and when do the cityField and centerField components get updated. It
is important that you show the interactions in the correct sequence and that the arrows originate
from the correct calling object and terminate on the correct called object.

2
<Paste your complete UML diagram here. >

<Paste your complete UML diagram here. >


In this diagram the user enters one or more cities, once he is done the Weather Action
Listener executes an Action performed. This sets the CityField Enabled to false, at which
time Weather Action Listener creates a new Fetch task that invokes the Fetch Task class
and proceeds to gather text from the city field, add it to the cityList Array, and continues

3
to fetch and until there is no more city information. At this point a url connection is
opened to openweathermap.org, and a inputstream is opened and the citylist is shared
with the url until the list is empty, at that time CenterText is updated with the weather
information for the city, the setEnabled(true) is set for the CityField, a return null iss sent
back to Fetch Task and the inputstream is closed, and the display is updated.

4
2. Pub/Sub (also called Observer) Design Pattern

Download the ProblemDesign.zip file. It contains 6 classes; App is the main class. Create a
Java project and copy the 6 classes into the project.

A palindrome is text that reads the same backwards as forwards. Examples are

tattarrattat
Never odd or even.
Do geese see God?
A Toyota! Race fast.. safe car: a toyota.

The application displays a window with 3 field, the user enters text in the center field and the
program shows the character count in the top field and determines if the text is a palindrome
and displays YES or NO in the lower field. The 3 field are implements as 3 views over a
common data model (using the Model-View-Controller pattern).

The program as written does not update the other fields when the text is entered.

Use the Publish/Subscriber pattern to finish the program. You will need to
define Publisher and Subscriber interfaces
decide which class(es) need to implement the subscriber interface. Remember that you
need a receive method on the subscriber.
the Data class should be the publisher and notify all subscribers whenever the text
changes.

<copy your source code for Publisher and Subscriber java interfaces
here>
***

5
Good News, the pub/sub works great(tThast what we want J). The not so
great news is I had brain freeze, for the textfield.setText(data).
Couldnt figure out how to use the different methods with them in the
subscribers

package dw;

public interface Publisher {


public void subscribe(Subscriber a);
public void unsubscribe(Subscriber a);

package dw;

public interface Subscriber {


public void receive(String data);

<copy your modifications to Data, ViewCount, ViewPalindrome, View


classes here>
package dw;

import java.util.ArrayList;
public class Data implements Publisher{
ArrayList <Subscriber> list = new ArrayList<Subscriber>();

private String data="";

public String getText() { return data;};

public void setText( String str) {


if (! data.equals(str)) {
data = str;
//test System.out.println(data);
// test System.out.println(CoinPurse);

for (Subscriber s : list)


{

6
s.receive(data);
}
}
}

public String getCountAsString() { return


Integer.toString(data.length() ); }

//test String CoinPurse=getCountAsString();

public void subscribe(Subscriber a)


{
list.add(a);
}
public void unsubscribe(Subscriber a)
{
int index = list.indexOf(a) ;
if ( index != -1) {list.remove(index);}
}

package dw;

import javax.swing.*;
public class ViewCount extends JPanel implements Subscriber{

public void receive(String data)


{

textfield.setText(data);
}

7
private JTextField textfield = new JTextField("", 10);

public ViewCount(String label, Data a) {


a.subscribe(this);
add( new JLabel(label));
textfield.setEditable(false);
add(textfield);
}

package dw;

import javax.swing.*;
public class ViewPalindrome extends JPanel implements Subscriber
{

private JTextField textfield = new JTextField("", 10);

public ViewPalindrome (String label, Data a) {


a.subscribe(this);
add( new JLabel(label));
textfield.setText( Palindrome.isPalindrome(a.getText() ) ?
"yes" : "no" );
textfield.setEditable(false);
add(textfield);
}

public void receive(String data) {

textfield.setText(data);

}
}

8
Explain describe the Publisher / Subscriber pattern. When do you use
it? How do you implement it?

We use the PUB/SUB to indirectly keep a path of communication


between classes in a application. We implement this buy having
one of the classes that handles the data to be the publisher.
This device pushes new information as needed to the
subscribers. Where the subscribers are subscribing to the
changes that the publisher is publishing. In order to make it
all work, there must be a subscriber interface, a publisher
interface, a class that implements the publisher interface, a
class that is a publisher, and class(s) that subscribe to the
ppublisher.

3. J2EE

a. In your own words describe what a Model-View-Controller pattern


is and how J2EE (JSP java server pages, Servlets, and JPA Entity classes)
implement this pattern.

The Model-View Controller pattern is a pattern that logically separates the


input, processing and output of the program. The Model portion
represents the Data (processing) portion of the application and is where
all the functions and methods that manipulate data are located. For
example, in our J2EE application this would be the hangman.java
component of our program. The View portion of the pattern is where the
output is located (display). For example, we used .jsp file for our output in
our j2ee hangman program. Finally the Controller portion is the part of the
program where interaction/input takes place, i.e server, model interaction.
Again, in the case of the J2EE program our MyServlet.java was the
controller piece to that application.

b. When writing a REST-JSON application, there are no JSPs that


create html. Can an MVC pattern still be applied to design and implementation of
a REST-JSON server application?

Yes the MVC Pattern can still be used in this case, since there is a
WEB.xml portion to handle the JSON output, so it is the View portion of
the MVC design pattern. If we look further into the web.xml file for the
above mentioned application, we will notice that there is a reference to
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-

9
class>. This mention class handles the output portion of the application.
Thus confirming that the MVC pattern can still be used.

4. Proxy Design Pattern

a. Read or review the description of the Proxy design pattern in


Marsic 2.6.4 page 264. Describe ways in which the TestHttpExchange class that
was used in Assignment 4 on Junit test of the Http Hangman game, is an
example of using the Proxy pattern.
In this case the testing pattern is a proxy pattern since it is the test in
a Junit test is simulating user interaction.

b. Describe one way in which the TestHttpExchange class is not an


example of the Proxy pattern according to the Marsic definition of Proxy pattern.

Since the TestHttpExchange used doesnt support simultaneous user


interaction with testing is a way that the TestHttpExchange is not as proxy
pattern.

c. Briefly describe one other situation where proxy objects would be


useful. It might be something that you coded for other courses but did not realize
at the time it was a Proxy pattern; it might be an example from the textbook; or
an example that you think up on your own.
The first thing that comes to mind is a user login page. The proxy is used
to validate things such as characters and string lengths before it sends
content to the host. This can and is a huge security benefit as well as a
convenience to users.

10

Вам также может понравиться