You are on page 1of 4

CS 4040 Software Architecture and Design

Assignment 2

P.R.A.I Gunarathna 070147T CSE

Introduction. I chose the project Character Frequency Analyzer for re engineering. This application was developed by me sometimes back and I realised that the architecture of the project is not up to the standards as well as I found many bad smells in the code. I did not have any understnading of these when I developed it. So I decided to re engineer the project and to re factor the bad smells. Character Frequency Analyzer can analyze the frequency of each character of a text inputted. This is designed for English language. Architecture before re engineering The architecture before re engineering is as follows. (Only the most relevant classes are shown)

User Interface Class

Main method Counter Method

Fileout method

Capital Class

Architecture after re engineering The above architecture was re engineered to arrive at best practices of software engineering. It is as follows.

Counter Class

User Interface Main method

Help Class

File Out Class

File In Class

Create Table Class

The work is distributed to many classes such as File Out, Create Table, Counter etc. Their tasks can be described as follows. User Interface : Previously main method and user interface were two classes. Later I realised that I could integrate both, since Main class alone could be identified as a lazy class. Counter Class : Initially counter method was in the user interface class. Counter method counts the frequency of each character. Now it is separated as a separate Counter class, unless User Interface class would be a long class, which is a bad smell. File Out Class : The task of the fileout method was to write the result to a text file and this also was integrated to the User Interface class. Due to the bad smell of long class, I separated it to a separate File Out class. Create Table Class : This would get data from FileIn class and display the summary results. (Useful when using many samples). This would gain input from File In class which would read a text file. The communication also was changed. Now the main class has control of all sub classes and sub classes also can communicate well. Bad Smells in the code and refactoring solutions. Following table would summarise. Bad Smell Example Lazy class Main class, the only work main class had been doing was calling for the There was a class called Capital class(not included in the design), it does not do anything other than giving capital letters for simple letter inputs, it was a test class Initially I have designed in such a way that class contained all the methods, this has made the code too complex and difficult to understand There is a class called, the count method had code to print the results while counting, this made the count method too long I had kept the class in the hope that I might need it, but it does not do anything, an extra overhead

Solution Combined GUI with main class (created main method in GUI,.ava class) Removed the capital class

Large Class

I made separate classes for each method, then those classes deal with only a specific task assigned, now each class looks simple and easy to understand I made a separate class called which would take care of writing the output, now the count method contains only the basic logic it requires Removed the class as it is an extra overhead

Long method

Speculative Generality

Comments class contained so many comments, since the methods were long, the code was opaque so many comments were needed to explain it After the first re engineering, I found that GUI class passes the information as constructers, no use of getter and setter methods Eg: FileOut (Filename, frequency[]......)

Seperated methods, now each method looks simple (Count, WriteFile, ReadFile etc), so less comments needed, now looks simpler to understand Need to create getter and setter methods for each newly added class Eg: FileOut.getFilename()

Inappropriate Intimacy

Alternative classes with different As previously said Main class I made GUI class as the main interfaces has not been doing anything. class, no removed the previous Main class had methods to do the main class. frequency count in the console input and output, while GUI also had the same capability under its GUI Divergent Change As previously said, I had been improving GUI class, so it contained most of the methods even methods for FileOut, so it made the class to heavy and complex Initially count() method contained a set of switch statements to check each letter whether it is A,B...Z. This was annoying. Reshuffled the GUI class and made separate classes for different tasks


I changed the logic, instead of checking for each letter in a switch statement, I introduced a loop to check and an array to get updated. (This solution is not the theoretical solution for switch statements, but I felt that this was the best solution under this context) It is prudent to use a 2 dimensional array which can store character as well as the frequency count. array[char][count] Eg: count{(a,44),(b,33),.....}

Primary Obsession

I still use a one dimensional array to store character frequency values. Its length is 26, array[0] value indicates the frequency of letter A(or a), array[1]- b and so on.