Thursday, May 15, 2014

TOOLS

Last week I visited the Computer Science Museum in Mountain View. I was surprised by the machines that were invited many years ago. So I am curious how these people can make it and I found that taking good advantage of the tools is the one of the most important reasons.


We must first sharpen our tools before we are going to start. A good tool to make the work more efficiently. Taking full advantage of tools is what I want to do in my study. For example, if I have a program to implement. At first, I have to design all classes in the program and figure out the relationship between them. So I will use a tool to draw the Class diagram and Use Case. After that, I can use a tool like UMLStar to draw the sequence diagram. The goal of doing these is to make me clear about the program before I start the code part. Then I implement the program by using the Eclipse. In one word, I can't do noting without tools.

I discovered some tools this semester like IntelliJ IDEA, Criterion, SWL, SWL-Prolog and UMLStar. IntelliJ IDEA is a Java IDE by JetBrains, available as an Apache 2 Licensed community edition and commercial edition.[1] Criterion is a essay writing evaluation tool. SWL is a Scheme IDE. SWL-Prolog is for Prolog programming.

My favorite tool is Eclipse, because it is very convenient to write code. There are some features that I often use. Formatting: ctrl+shift+f. Format source file (set up your formatting style in Window | preferences | java | code style | formatter). ctrl+shift+o: Organise imports. Generated code
alt+s,r to generate getters and setters and alt+s,v to insert method signatures for overidden methods from superclass or interface.[2] The tool I like least is SWL. SWL is a very clear IDE without any good user interface. Sometimes I feel boring when I use it.

Tools are changing very fast. They are becoming smarter than we can imagine, also the tools look more beautiful than before. There is no doubt that development of tools is very important to the industry. A good tool can save a lot of time for the developers and therefore the developers can spend more time to think about how to make the program better instead of figure out how to implement the programs. As a result, the IT industry will develop faster and faster. In this way, more and more people will begin study in CS area and enter the IT industry. So it is a cycle that can make a more stable and sustainable development model.

References:
[1] Wikipedia,
http://en.wikipedia.org/wiki/IntelliJ_IDEA
[2] Stackoverflow.com
http://stackoverflow.com/questions/20529/useful-eclipse-features

Tuesday, May 13, 2014

Abstract Class In Java

We often see the word "abstract" when we are reading the code. The reader often has a question that what this word is. So I will give a simple example to explain how the abstract works.

There is a interface named SceneShape(see Figure 1):

public interface SceneShape
{
      void setSelected(boolean b);
      boolean isSelected();
      void draw(Graphics2D g2);
      void drawSelection(Graphics2D g2);
      void translate(int dx, int dy);
      boolean contains(Point2D aPoint);
}


                                        Figure 1. The Scene Editor 

                                        Figure 2. A CRC Card

Then define  classes CarShape and HouseShape that implement this interface type. However, there is some commonality between these classes. Every shape needs to keep a selection flag.[1] The naive approach would be to supply the selection flag separately in each class:

public class HouseShape implements SceneShape
{
     ... ...
      public void setSelected(boolean b) { selected = b; }
      public boolean isSelected() { return selected; }
      private boolean selected;
}

public class CarShape implements SceneShape
{
      ... ...
      public void setSelected(boolean b) { selected = b; }
      public boolean isSelected() { return selected; }
      private boolean selected;
}

If we create a class that expresses this commonality and we call this class SelectableShape.

public class SelectableShape implements SceneShape
{
      public void setSelected(boolean b) { selected = b; }
      public boolean isSelected() { return selected };
      private boolean selected;
}

As we can see, there is a problem with the SelectableShape class. It doesn't define all of the methods of the SceneShape interface type. There are four methods left in this class. So we can say that these methods are undefined or abstract in the SelectableShape class. It is the job of further subclasses to define them.[2] For that reason, the SelectableShape class must be tagged as abstract:

public abstract class SelectableShape implements SceneShape { ... ... }

Abstract classes are convenient placeholders for factoring out common behavior. They behave exactly same as any other classes. I am often scared about abstract classes, equating "abstract" with "hard to understand", and then believing that any class that is hard to understand should therefore be abstract. After using the abstract class many times, I find that abstract class is simply a class that cannot be instantiated, generally because its has unimplemented methods.


References:
[1] San Jose State University, Suneuy Kim,
http://cs.sjsu.edu/~kim/cs151/index.html
[2] San Jose State University, Cay Horstmann,
http://www.sjsu.edu/people/cay.horstmann/