《软件体系结构与设计模式》大作业报告

《软件体系结构与设计模式》大作业报告

Homework 2: 抽象工厂模式(Abstract Factory Pattern)

作业描述:

The following class diagram represents a design in abstract factory pattern to query about the features of different types of buildings. See the source code for the implementation of the following class diagram.

  1. Run the AbstractFactoryGUI first to be familiar with the program
    《软件体系结构与设计模式》大作业报告_第1张图片
  2. In the avove design, add a class hierarchy named SemiDetacher with 2 subclasses named SupSemiDe and MedSemiDe and similar interface and methods as class hierarchy House and class hierarchy Condo do.
  3. Then you need to modify the corresponding part in the class BuildingFactory and its subclass to allow the objects of subclasses of SemiDetacher be created
  4. Implement the modified class diagram, adding possible code as needed.
  5. Run object of the class AbstractFactoryGUI to test the program with new function.

作业报告部分

  1. Describe your finished homework.
    a) Tell me what classes have you added to the existing class hierarchy?
    b) Explain the relationship between the existing classes and the newly added classes.
    a) Interface SemiDetacher, class SupSemiDe, and class MedSemiDe.
    b) Class SupSemiDe and class MedSemiDe implement the Interface SemiDetacher. MediumFactory creates class MedSemiDe, SuperFactory creates class SupSemiDe.
  2. Draw your new class diagram here
    《软件体系结构与设计模式》大作业报告_第2张图片

(关于图片,不太好意思,上传的时候就调整了方向,上传后却变成了这样,调整了很长时间都没有旋转过来,有知道怎么办的可以评论哦)

3. When a user chooses semi-detatcher and click on search, what methods will be called? List all of them in correct order.
a) getFactory()
b) getSemiDetacher()
c) getSemiDetacherInfo()
4. After you add the required class SemiDetacher hierarchy,
a) What classes in the BuildingFactory class hierarchy have been affected?
b) What methods have you added to the class hierarchy?

a) Class MediumFactory, Class SuperFactory, Class BuildingFactory have been affected
b) An abstract method getSemiDetacher() has been added to abstract class BuildingFactory, class SuperFactory and class MediumFactory both add a method getSemiDetacher() and implement them at the same time.
5. Discuss the similarity and differences between factory method pattern and the abstract factory pattern in no more that 120 words.
Similarity:
They both encapsulate the process of object creation into a factory class, so that client class has no direct access to create the concrete class.
Differences:
Their production are different, factory method pattern produce a single product class hierarchy; however, abstract factory pattern produce a group of product class hierarchies.
The factory method pattern follows open-closed principle, while the abstract factory pattern only partially follows the open-closed principle.
6. Discuss about the method getFactory(String type) in the class
BuildingFactory.

a) What is the functionality of this class?
b) If we cancel this method from class BuildingFactory, then what do we need to do in the class AbstractFactoryGUI?
c) Point out advantages of the method getFactory(String type).
a) To create SuperFactory class or MediumFactory class.
b) We need to Create an instance of BulidingFactory class and transition it down to SuperFactory class or MediumFactory class.
c) ClientCUI class could create objects representing houses of different types and categories through different kinds of factory without having to know the actual concrete class that needs to be instantiated. Also, in the ClientGUI, we have no necessary to write a lot of conditional statements to choose which factory, so that it is benefit for us to extend and maintain.

Homework 4: 桥接模式(Bridge Pattern)

作业描述(特工信息保密系统):

The following design represents an agent information system. Agents’information should be encrypted and then saved into a text file or a database. There are two ways to encrypt agent’s name and code number, represented by classes EncryptedInfo1 and EncryptedInfo2.
EncryptedInfo1的加密算法:折叠算法

  1. 将26个英文字母按照顺序排列,加密的时候,以折叠的方式进行:
    a⬅➡z, b⬅➡y, …,m⬅➡n
  2. 大写字母也是如此。大写字母加密为大写字母。
  3. 数字加密也以此方式进行0⬅➡9,1⬅➡8,2⬅➡7,3⬅➡6, 4⬅➡5
    《软件体系结构与设计模式》大作业报告_第3张图片
    EncryptedInfo2的加密算法:分组互换算法
    1. 将26个英文字母按照顺序排列,按照如下方式两两分成一组,本组内部加密的时候互换: a⬅➡b, c⬅➡d,…, w⬅➡x, y⬅➡z。
    2. 大写字母的加密方式也是如此,大写字母加密为大写字母。
    3. 数字加密:0⬅➡1, 2⬅➡3,4⬅➡5, 6⬅➡7, 8⬅➡9

《软件体系结构与设计模式》大作业报告_第4张图片
程序运行界面如下

设计类图如下

Fig. 1 Design class diagram for agent information system
Your task:
You are required to write a class EncryptedInfo3 to encrypt agent’s last name, first name and code number.
a) The class should be in the same format as EncryptedInfo1 and EncryptedInfo2, and provide a different encryption method
b) EncryptedInfo3 should encrypt the last name, first name and code number as described below as CaesarCypher: To encrypt a word, we replace the letter a with b, b with c, and so on, up to z, which is replaced by a. This is called the rotate-1 Caesar cipher. When a digital number between 0 and 9 is encountered, the rule to rotate is 01, 12,…,89 and 90. For example:
Plain text: Mike
Encrypted text: Njlf
Plain text: Sun
Encrypted text: Tvo
Plain text: Shanben56
Encrypted text: Tibocfo67
c) Modify the class ClientGUI to allow choice EncryptedInfo3 to be shown in the GUI.

 Note: 特工密码长度为12位,由英文字母与0,1,…,9阿拉伯数字组成。
 The length for a code is exactly 12, formed by mixed characters and digital numbers.

作业报告部分

  1. Describe your finished homework, including
    a) What classes have been added to the existing class hierarchy?
    b) Explain the relationship between the existing classes and the newly added classes.
    a) Answer: Add a new derived class inherited from the parent class Agent Info class, namely EncryptedInfo3 class.
    b) Derived classes EncryptedInfo3 inherited from the parent class AgentInfo. Class EncryptedInfo3 aggregate class MessageWriter.

  2. Draw your new class diagram here

  3. Answer questions as below: after you add class EncryptedInfo3,
    a) Do you need to recompile class EncryptedInfo1 and EncryptedInfo2?
    b) Do you need to recompile class AgentInfo?
    c) Do you need to recompile class FileWriter or DBWriter?
    a) Answer: No, we needn’t, we haven’t changed the EncryptedInfo1 and EncryptedInfo2 classes, we just add a class named EncryptedInfo3 parallel to them.
    b) Answer: No, we just call the AgentInfo class without modifying it.
    c) Answer: No, we just call FileWriter and DBWriter without modifying them.

  4. In class EncryptedInfo1, there is a constructor
    public EncryptedInfo1(MessageWriter l){
    writer = l;
    }
    Why do we use type MessageWriter as the parameter type and why don’t we use type FileWriter or DBWriter as the parameter type?
    Answer: use type MessageWriter can decouple Abstraction and Implementor also eliminates compile-time dependencies on the implementation.We doesn’t need to recompile the Abstraction class and its clients when changing an implementation class . We don’t need to recompile any classes if we add a class parallel to FileWriter or DBWriter.

  5. In class ClientGUI , we have the source code
    MessageWriter writer;

    if( logWay.compareTo(ClientGUI.DBWRITER)==0 )
    writer = new DBWriter();
    if( logWay.compareTo(ClientGUI.FILEWRITER)==0 )
    writer = new FileWriter();
    What is the advantage of writing code above?
    Answer: The implementation of an abstraction can be configured at run-time.

  6. If we add a class named ConsolWriter parallel to DBWriter, do we need to recompile any classes?
    Answer: Except for GUI classes that need to recompile some additional conditional statements, other classes do not need to recompile.

  7. Test your finished program. List your test input and output from running your program.

Homework 7: 状态模式(State Pattern)

作业描述:

See the following class diagram for the State pattern implementation of Bank.

Fig 1. class diagram of Bank account in the State pattern

Fig 2. the state transition diagram for the Bank problem

Fig 3. the graphical user interface produced when class AccountManager is run
The class BankContext acts as the Context class in the State Pattern and class ClientGUI is the client class. Read the source code carefully and then do the following:
Add a new class called TaxState to subclass the State class. Use the algorithm as below:
When balance >= 100000, the program runs into TaxState. Under this state, every newly deposited amount of money will be charged 5% for the tax (the tax will be paid to the government, however, we ignore this part and just deduct 5% for newly deposit amount of money ) .

作业报告部分

  1. Describe your finished homework, including
    a) What classes have been added to the existing class hierarchy?
    b) Specify the relationship between the existing classes and the newly added classes.
    a) A new class named TaxState has been added.
    b) The class TaxState is the subclass of the abstract class State, the same as the other three subclasses.

  2. Draw your new state diagram here

  3. When you fill in “deposit” in the in the transaction type, and when you fill in the money amount like 2500, what statements in the class ClientGUI will be invoked. Also trace back all the statements called in class BankContext and class State and its subclasses.

  1. In ClientGUI:
    public void actionPerformed(ActionEvent e) {
    String searchResult = null;
    boolean result = false;
    searchResult = “\n\nOriginal Balance=” + accContext.getBalance() +
    “\n” + "Original State = " + accContext.getState() + “\n\n”;
    setResult(searchResult);

if (e.getActionCommand().equals(EXIT)) {
// Won’t be invoked.
System.exit(1);
}
if (e.getActionCommand().equals(SUBMIT)) {
String type = getTransactionType();
String amount = getTransactionAmount();
if (type.equals(DEPOSIT)) {
accContext.deposit(new Double(amount).doubleValue());
}
if (type.equals(WITHDRAW)) {
// Won’t be invoked.
accContext.withdraw(new Double(amount).doubleValue());
}
searchResult = “Transaction Successful: \n” + “New Balance=” +
accContext.getBalance() +"\n" + "New State = "

  • accContext.getState();
    if (accContext.isOverDrawnLimitHit() == true)
    // Won’t be invoked.
    searchResult = BankContext.ERR_OVER_LIMIT;
    setResult(searchResult);
    }
    }
  1. In BankContext:
    public String getState() {
    return objState.getState();
    }

public void setStateObj(State objState) {
this.objState = objState;
}

public void deposit(double amount) {
if (amount > 0) {
objState.setContext(this);
objState.deposit(amount);
} else {
// Won’t be invoked.
System.out.println(“Deposit amount cannot be 0 or negative”);
}
}

public double getBalance() {
return balance;
}

public void updateBalance(double balance) {
this.balance = balance;
}

public boolean isOverDrawnLimitHit() {
return objState.isOverDrawnLimitReached();
}
3) In State:
protected void changeState() {
balance = context.getBalance();
if (balance < 0 && balance >= BankContext.OVERDRAW_LIMIT)
// Won’t be onvoked.
state = OVERDRAWNSTATE;
else if (balance >= BankContext.MIN_BALANCE
&& balance < BankContext.TAX_BALANCE)
state = NOFEESTATE;
else if (balance >= 0 && balance < BankContext.MIN_BALANCE)
// Won’t be invoked.
state = FEESTATE;
else if (balance >= BankContext.TAX_BALANCE)
// Won’t be invoked.
state = TAXSTATE;
else
//Won’t be invoked.
state = ERRORSTATE;
passStateObjToContext();
}

public void passStateObjToContext() {
if (state.equals(OVERDRAWNSTATE))
// Won’t be invoked.
stateObj = new OverDrawnState();
else if (state.equals(NOFEESTATE))
stateObj = new NoTransactionFeeState();
else if (state.equals(FEESTATE))
// Won’t be invoked.
stateObj = new TransactionFeeState();
else if (state.equals(TAXSTATE))
// Won’t be invoked.
stateObj = new TaxState();
context.setStateObj(stateObj);
}

public String getState() {
return state;
}

public void setContext(BankContext context) {
this.context = context;
}
4) In TransactionFeeState:
@Override
public void deposit(double amount) {
if (amount > 0) {
balance = context.getBalance() - BankContext.TRANS_FEE_NORMAL;
balance = balance + amount;
context.updateBalance(balance);
changeState();
} else {
// Won’t be invoked.
System.out.println(“Deposit amount cannot be 0 or negative”);
}
}

@Override
public boolean isOverDrawnLimitReached() {
return overDrawnLimitFlag;
}
5) In NoTransactionFeeState:
public NoTransactionFeeState() {
state = NOFEESTATE;
}
4. What methods in what classes are used to keep the communication between the State class hierarchy and the context class BankContext

  1. In class BankContext:
    public BankContext(State st, String accountNum) ;
    public void deposit(double amount);
    public void withdraw(double amount);
    public double getBalance();
    public void updateBalance(double balance) ;
    public boolean isOverDrawnLimitHit();
  2. In State class hierarchy:
    protected void changeState();
    public void passStateObjToContext();
    public String getState();
  1. When you add the new required class TaxState, what methods in what classes
    also have to be modified.
  1. In class BankContext:
    Add a constant:
    public static final double TAX_BALANCE = 100000.00;
  2. In class State:
    a) In method changeState():
    Modified one condition:
    else if (balance >= BankContext.MIN_BALANCE
    && balance < BankContext.TAX_BALANCE) {
    state = NOFEESTATE;
    }
    Add one new case:
    else if (balance >= BankContext.TAX_BALANCE) {
    state = TAXSTATE;
    }
    b) In method passStateObjToContext():
    Add one new case:
    else if (state.equals(TAXSTATE)) {
    stateObj = new TaxState();
    }

Homework 9: 中介者模式(Mediator Pattern)

Homework Description:

See the following class diagram for the Mediator pattern implementation of collaboration program for Hotel, Airline and Tour.

图1 利用中介者模式设计的信息共享程序
The three graphical user interfaces for the Hotel, Airline and Tour are as below.

图2 旅游公司输入客户信息

图3 宾馆界面同步获得旅游公司输入的客户信息

图4 机场界面同步获得旅游公司输入的客户信息
当在一个用户图形界面,例如Tour,中输入Mike Lee,1239852,选择USA,然后点击按钮“Submit”,则程序会通过BusinessMediator对象,将这些客户信息转发给Hotel和Airline对象,并且显示在相应的用户图形界面上。这些客户数据也被写到了以下的数据文件TourCustomer.xml,HotelPossibleCustomer.xml和AirportPossibleCustomer.xml中。
Homework requirement:

  1. Run the program before you go any further
  2. (Coding) Add another class named TouriststoreGUI (旅游商店)such that the 4 classes HotelGUI, AirflightGUI, TourGUI and TouriststoreGUI will interact though the BusinessMediator in the same way as before (use the mediator pattern).

作业报告部分

  1. Describe your finished homework, including
    a) What classes have been added to the existing class hierarchy?
    b) The relationship between the existing classes and the newly added classes
    a) Answer: We added class TouriststoreGUI to the existing class hierarchy.
    b) Answer: Class TouriststoreGUI is like class HotelGUI, AirflightGUI, TourGUI and TouriststoreGUI, is a derived class of class ParticipantGUI.

  2. Draw the final class diagram here

  3. In HotelGUI object, when you enter name entry as “Rose Black”, id number entry as “555888999”, and choose the nationality as “USA”, and then click on button “Submit” to save the customer information into file HotelCustomer.xml, what methods in what class will have been invoked, list all of them in correct order.
    Answer: When click on button “Submit”:
    Firstly, the writeCusToXmlFile method is invoked in class HotelGUI.
    Secondly, the askMedSaveCusInfo method is invoked in class HotelGUI.
    Thirdly, the writePossibleCustoXmlFile method is invoked in the BusinessMediator class.
    Forthly, the writeCandidateCustoXmlFile method is invoked in the airlineGUI class, HotelGUI class, TourGUI class and TouristStoreGUI class in turn.
    Finally, the addCustomer method, askMedAddCus method and askMedUpdate method is invoked in the class Hotel.

  4. Discussion
    a) Describe the functionality of the BusinessMediator class.
    b) Explain how the mediator pattern works?
    c) How the method updateAllGuis(ParticipantGUI p, String text) in the BusinessMediator class works?
    a) Answer: BusinessMediator class abstracting all object interaction details. BusinessMediator keep a reference of each of the interacting objects and provide methods to call the participating objects, such as HotelGUI, AirflightGUI and so on.
    b) Answer: mediator pattern requests the interaction between any two different objects is routed through the Mediator class. All objects send their messages to the mediator by calling methods of Mediator. The mediator then sends messages to the appropriate objects to implement the application’s requirements. Finally, the mediator invokes the methods of all other actors participated.
    c) Answer: method updateAllGuis through an iterator, the displayInfo method of each bound participant object is called in turn.

  5. [Extendibility Issue] Discussion:
    a) After you add the new class TouriststoreGUI, do you have to modify class ParticipantGUI?
    b) After you add the new class TouriststoreGUI, do you have to modify class HotelGUI?
    c) After you add the new class TouriststoreGUI, do you have to modify class AirlineGUI?
    d) After you add the new class TouriststoreGUI, do you have to modify class TourGUI?
    e) After you add the new class TouriststoreGUI, do you have to modify class BusinessMediator?
    a) Answer: No, we don’t have to. Expanding a subclass does not need to modify the code of the parent class.
    b) Answer: No, we don’t have to. Class TouriststoreGUI just calls class HotelGUI’s methods through the mediator class.
    c) Answer: No, we don’t have to. Class TouriststoreGUI just calls class AirlineGUI’s methods through the mediator class.
    d) Answer: No, we don’t have to. Class TouriststoreGUI just calls class TourGUI’s methods through the mediator class.
    e) Answer: No, we don’t have to modify class BusinessMediator.

Project 1: Encryption by Using Layered Architecture

问题描述:

The purpose of this project is to design an agent information system by using three-layer layered architecture. The agent information is encrypted and then saved into some specific text files. In the design below, the graphical user interface includes a class nemed ClientGUI for sending user’s request. The application layer contains a class hierarchy named Encryption to actually encrypt agent info and calls class TxtFileWriter, which saves the encrypted data into files Folding.txt, and Group-swap.txt. The agent information to be encrypted includes agent’s last name, first name, and agent code. The agent code can be mixed characters with digital numbers. The length of the code is 12.

Fig 1. Software architecture for the agent information system
Note that we can think class hierarchy named encryption in the application layer forms a strategy design pattern (without the context class).
算法描述:
Class EncryptedInfo1 encrypts agent information using Encryption Algorithm1 (折叠算法) as below.
Precondition: a text file to be encrypted contains only English characters and digital numbers. The algorithm is:
az, by, …mn, yb, za
09, 18, 27, 36, 45, 54, 63, 72, 81, 90
Upper case letters are also encrypted the same way (Upper case letters are encrypted into Upper case letters).

Class EncryptedInfo2 encrypts agent information using Encryption Algorithm2 (分组互换算法).
Precondition: a text file to be encrypted contains only English characters and digital numbers. The algorithm is:
ab, ba; cd, dc; ef, fe;, …, yz, zy
01, 10; 23, 32; …89, 98
Upper case letters are also encrypted the same way (Upper case letters are encrypted into Upper case letters) .
Class diagram is as Fig 2.

The souce code for the above class diagram has been written in Java. The encrypted agent information from EncryptedInfo1 is saved into a file named Folding.txt and encrypted agent information from EncryptedInfo2 is saved into a file named Group-swap.txt. Both text files are in the same folder as the Java source files.

Fig 2. The class diagram for the agent information system

你的任务:

  1. 在以上已经存在的设计中,新增加第三种加密算法. Now you are required to write a class EncryptedInfo3 to encrypt agent’s last name, first name and code number.
    a) The class should be in the same format as EncryptedInfo1 and EncryptedInfo2, and provides a different encryption method
    b) EncryptedInfo3 should encrypt the last name, first name and code number as described below as CaesarCypher: To encrypt a word, we replace the letter a with b, b with c, and so on, up to z, which is replaced by a. This is called the rotate-1 Caesar cipher. When a digital number between 0 and 9 is encountered, the rule to rotate is 01, 12,…,89 and 90. For example:
    Agent first name: Mike
    Encrypted agent first name: Njlf
    Agent last name: Sun
    Encrypted agent last name: Tvo
    Agent code: WildWolf7489
    Encrypted agent code: XjmeXpmg8590
    c) Modify the class ClientGUI to allow choice EncryptedInfo3 to be shown in the GUI.
    d) The encrypted agent information should be saved into a text file Caesar.txt.

  2. 在应用层,增加相应的解密算法层次类Decryption,该类带有三个相应的解密子类。分别从三个加密文件中读出的agent加密信息,可以通过此层次类解密,然后显示在用户图形界面上。

  3. 在用户图形界面上增加解密按钮,以便对各个加密文件所存的内容进行解密,然后显示的用户图形界面上。

【注】为了方便起见,你也可以使用另外一个文件夹包含全部的解密程序和text文档。

项目报告部分

  1. Draw your software architecture for your new agent information encryption system

  2. Draw class diagram for your new agent information encryption system

  3. To implement all the required functionalities, what classes have you added to the application layer?
    Answer: We add class EncryptedInfo3 to encrypt agent’s last name, first name and code number. We add class Decryption with three subclasses, named class DecryptedInfo1, DecryptedInfo2 and DecryptedInfo3, to decrypt the file and display it on the user graphical interface.

  4. Which design pattern has been used in the application layer?
    Answer: Strategy Pattern has been used in the application layer. When a new decryption algorithm is added, the existing class hierarchy doesn’t need to be changed and recompiled.

  5. Answer question: When you add a new class in the application layer, will the data file access layer be affected or not?
    Answer: It will not be affected. The application layer only calls the data of the data storage layer, and the specific implementation is in the application layer.

  6. Answer question: When you add a new class in the application layer, will the user interface layer be affected or not?
    Answer: It will not be affected. The user interface only needs to add a new Button to call the new services of the application layer, and the specific implementation is carried out in the application layer.

  7. Answer question: When you add a new method in the TxtFileWriter class, will the user interface layer or the application layer be affected or not?
    Answer: It will not be affected. The user interface layer and application layer call the services of the next layer, and do not care about the specific implementation of the next layer.

  8. If you want the user interface layer to initialize a request to save some data into the data files, what classes need to call?
    Answer: We need to call class Encryption and class TextWriter, the user interface layer calls the log method of class Encryption in the application layer, which calls textwriter’s write file method.

  9. In your program,

  1. Does the application layer call the user interface layer?
  2. Does the data files access layer call the application layer or the user interface layer?
  3. Answer: No. The interaction of the three-tier architecture is linear, and the user interface layer calls the application layer. Calls in the opposite direction are not allowed.
  4. Answer: No. The lower layer cannot call the upper layer’s service. The interaction between the three-tiers architecture is linear.
  1. 测试与验证部分: List at least 3 group of typical input and output from running your program, corresponding to 3 ways to encrypt and decrypt agent information

Project 3: Text File Encryption in Pipes-and-filters Architecture

项目需求部分:实现一个多次加密程序

Do text file encryption by using the pipes and filters architecture. Suppose that we have 3 encryption algorithms as following:
Encryption Algorithm 1 (折叠算法). Precondition: a text file to be encrypted contains only English characters and digital numbers. The algorithm is:
az, by, …mn, yb, za
09, 18, 27, 36, 45, 54, 63, 72, 81, 90
Upper case letters are also encrypted the same way (Upper case letters are encrypted into Upper case letters).
Encryption Algorithm 2(分组互换算法). Precondition: a text file to be encrypted contains only English characters and digital numbers. The algorithm is:
ab, ba; cd, dc; ef, fe;, …, yz, zy
01, 10; 23, 32; …89, 98
Upper case letters are also encrypted the same way (Upper case letters are encrypted into Upper case letters) .
Encryption Algorithm 3 (Caesar cipher, rotation 1): Precondition: a text file to be encrypted contains only English characters and digital numbers. The algorithm is: for the 26 English characters, you replace the letter a with b, b with c, and so on, up to z, which is replaced by a. When a digital number between 0 and 9 is encountered, the rule to rotate is 01, 12,…,89 and 90.
ab, bc; cd, de; ef, …,yz, za
01, 12; 23, 34; 45, 56,67,78, 89, 90
Upper case letters are also encrypted the same way (Upper case letters are encrypted into Upper case letters)
The program should be designed using pipes and filters architecture, which contains filters as below:

  1. InFilter reads the file to be encrypted in character stream format and parses the file. The parsed data is written to the output pipe as char stream;
  2. EncrFilter1 reads character stream from its source pipe, use Encryption algorithm 1 to encrypt the incoming characters and numbers, and then write the resultant data into sink pipe as character stream;
  3. EncrFilter2 reads character stream from its source pipe, use Encryption algorithm 2 to encrypt the incoming characters and numbers, and then write the resultant data into sink pipe as character stream;
  4. EncrFilter3 reads character stream from its source pipe, use Encryption algorithm 3 to encrypt the incoming characters and numbers, and then write the resultant data into sink pipe as character stream;
  5. OutFilter reads character stream from the source stream (through source pipe), and then write the resultant data into a file named Updated.txt in directory “EncryptedFiles” and onto the right textArea on the GUI (the original file content will be shown on the left textArea)
    The logic design of the pipeline is as the following.

Fig 1. The logical design of the encryption system

The class diagram design is as below.

Fig 2. The design of encryption program using pipes and filters architecture
你的任务:

  1. 在以上设计中,InFilter类,EncrFilter1类,和OutFilter类已经实现。你的任务是写代码实现EncrFilter2类和EncrFilter3类(提示:在写代码之前,运行程序,会对你的理解有所帮助)。
  2. 要求你的经过3次复合加密过滤器处理的文件,显示在图形界面右端的文本框中和相应的文件夹EncryptedFiles中的相应的文件EncryptedSalesman1, EncryptedSalesman2,或者EncryptedSalesman3之中。
  3. 与加密类似地,按照以上类似的管道-过滤器架构设计并且实现一个针对以上算法的解密系统,可以将以上的整个加密程序,包括用户图形界面类,复制为另外一个文件夹,然后少许修改代码,而成为一个解密系统。注意,解密系统的过滤器的顺序与加密系统过滤器的顺序相反。
  4. 对解密系统进行测试:使用已经被三次加密的数据,进行解密运算,如果最后得到未加密之前的原始数据,则说明你的加密系统是正确的(目的是验证你的加密算法的正确性)。

项目报告部分

  1. Answer question: When you add a new sub class of Filter, what class needs to be modified in order for using the new sub class?
    a) The AssemblyOfPipeLines Class has been modified.
    b) Two filters (filter2 and filter3) and two pipes (connecting filter1 and filter2, connecting filter2 and filter3) are added.
    c) The original pipes connecting filter1 and outfilter are changed to connect filter3 and outfilter.
  2. Answer question: What makes the data flow through the pipeline?
    The PipedReader reads data from the pipe, and the PipedWriter writes data to the pipe. An instance of the Pipe class is a composition of two streams: an input and an output stream. The data that is written to the input stream is transmitted to the output stream. In this way, these data become available for reading from the output stream.
  3. Answer question: What “all the filters can work simultaneously” mean?
    All filters work in multithreaded mode at the same time, they all have multi-thread properties. Filter class implement interface Runnable.
  4. 验证部分
  1. List typical input and output from running your encryption program
  2. use your decryption system to decrypt the output file from encryption to get the original file (如果你解密以后得到了原始文件,则证明你的加/解密算法的实现是正确的).
    If we input the content as following: “A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9”, we can get the result: “Z A X Y V W T U R S P Q N O L M J K H I F G D E B C 9 0 7 8 5 6 3 4 1 2”. Vice versa.

你可能感兴趣的:(软件工程)