Archive for May, 2009

North Korean Issue

Posted in world issus on May 31, 2009 by Asanga Bandara Wijekoon

These days North Korea does lot of military based researches and some of them are nuclear ones. By the way USA and some of other European countries blamed for that. So I though to talk about this topic.

We all know UK accepts anything if its came form USA side and actually that is a shame for them. American (USA people) came form UK but they challenge UK on long time ago and finally they won the freedom form the UK. Now its seems like UK struggling to get rid from USA governing on UK and though they accepting anything told by the USA. So afterward I don’t think world should consider the what the UK saying because they only append the part of “We are with you” to the Americans decisions. By the force of this economical crisis USA was fallen and before that by the help of Tony Blear and other leaders, UK also faced the economical difficulties. Anyway USA has the ability to survival from this crisis and UK also should have a way to get rid of it. So they are try to create good relationship with the USA and get the advantages of that and it seems like other European countries are not too much worried about UK. We all know what UK did when Europeans were went to the Euro. So the reason to talk more about the USA and UK they are the main opposite parties in the North Korean issue. I have a doubt that both these countries do have the ethical right to reject the North Koreans doings. They are talking a world of peas and we all seen what they did to Iraq and Afghanistan and earlier to Vietnam.

After the World War II, Soviet Union and United State troops controlled the northern and southern halves of the country respectively by defeating the Japan. Northern part lead to a communist country and southern part lead to more open economical governing. Actually Korea is one of a best symbol which represent worlds main two governing forces. I don’t think Koreans need to live in two separated countries. It seems powerful countries made this wound and now all the Koreans had to bear this wound and they need to cure from this. Japan is the side of USA in most of the time and china and Russia are main threat for USA. So USA help as much as they can to protect South Korean government and China and Russia help for North Korea to protect communist government and by doing that they also revenging from USA.

Last week North Korea did a nuclear research under the land. They said it was succeed. Anyway South Korea has reactors and they make electricity by use of them and still North Koreans try to engage the reactors for the electricity producing. Both countries has the nuclear power. Anyway North Korea stands now on eight place in the nuclear weapons power and they has great and powerful ground army near 1,000,000. I am adding some important details comparing North and South Korean military power.

_45837223_ns_korea466x224

Based on these facts it is obvious that South Korean have the fear on North Korea. Now its seems like other countries like China also considering this issue and they  told they are not accepting the research done by the North Koreans. Anyway if USA or China can do the nuclear experiment why  North Korean can not do. One time India told that to USA as an reply when they doing the “Agni” missal experiments and USA opposed to that.

What I feel now is most of the countries try to increase their military power. Not only North Korea but also India (baying AWACAS planes), Pakistan, Israel, China ( they also going to increase the power of their navy), Iran, etc. So are they ready for the another world war?

Observer Pattern

Posted in Design Pattern with Java, C++ and Ruby on May 30, 2009 by Asanga Bandara Wijekoon

First of all I need to emphasis that any pattern does not depend on a language and actually it is a powerful concept. Programmer should have the ability to format it according to the language going to use. My first explanation is based on Observer Pattern. This pattern use to implement to one-to-many relationship. Here we have a subject object and if its state is changed it inform to all the observer objects.  Let me explain it first using Java.
In Java we have pre implemented way of this pattern but I think its better to explain how we implement this pattern on our hand with better suiting to our interest and after that I explain how to use the lava pre-implemented pattern implementation.
First we define an interface for create concrete subject class. Here I need to note that we always try to code for an interface and not use concrete classes. This is good programming practice and it helps to manage code very much and dynamic object creation. Basically this interface and concrete class is for doing the a server kind of a job by managing the observers and they are some sort of clients.

public interface Subject {
public void registerObserver(Observer o);

/* observers are the clients who were been updating when subject status were changed*/
public void removeObserver(Observer o);
public void notifyObservers();
}

Now we are defining the ConcreteSubject class.
import java.util.*;
public class ConcreateSubject implements Subject {
private ArrayList observers;
public ConcreateSubject() {
observers = new ArrayList();
}
public void registerObserver(Observer o) {
observers.add(o);
}
public void removeObserver(Observer o) {
int i = observers.indexOf(o);
if (i >= 0) {
observers.remove(i);
}
}

public void notifyObservers() {
for (int i = 0; i < observers.size(); i++) {
Observer observer = (Observer)observers.get(i);
observer.update();
}
}
}

Now we need to inform the updates to the observers. To implement that I used an interface named it as Observer. Here one to many relationship perform as one subject relate to many observers.

public interface Observer {
public void update();
}

Now we are implement it using concrete observer class.
public ConcreteObserver implements Observer {
public void update(){
System.out.println(“updated”);
}
}

So that’s it. Now we are considering the Java inbuilt observer pattern support. Resource classes are available in the java.util package. Here we have Observable interface works as the Subject interface in our previous example and Observer is as normal Observer as in our previous example. (source codes of below examples took from http://www.java2s.com/Code/Java/Design-Pattern/Observableandobserver.htm)

import java.util.Observable;
import java.util.Observer;

public class MessageBoard extends Observable {
private String message;

public String getMessage() {
return message;
}

public void changeMessage(String message) {
this.message = message;
setChanged();
notifyObservers(message);
}

public static void main(String[] args) {
MessageBoard board = new MessageBoard();
Student bob =  new Student();
Student joe = new Student();
board.addObserver(bob);
board.addObserver(joe);
board.changeMessage(“More Homework!”);
}
}

class Student implements Observer {
public void update(Observable o,  Object arg) {
System.out.println(“Message board changed: ” + arg);
}
}