Great JOKES: JAVA OO design 5 5 1

Great JOKES: JAVA OO design

View previous topic View next topic Go down

Great JOKES: JAVA OO design

Post by BIT0112-Rokon on Sun Apr 04, 2010 10:30 am

class java{
public static void main(String[] args){
System.out.println("We all now very much familiar about Java Object oriented Design which is invented by the intelligent monkeys working at Sun Microsystems.");
}
}

by the way.. Java may seem to you a kind of joke while you are doing simple program with OOD. Okay now lets see a example;
Now Im going write a program with java as well as object oriented Design which will print a single line;
that is "Hell world";

Code:
package com.rokon;

public class HelloWorld1 {
   private String countryLang;
   private String[] hellowWorldArray = { "Hello World", "¡Hola, mundo",
         "Bonjour tout le monde", "مرحبا العالم", "नमस्ते दुनिया",
         "أهéل َلٍ êüَىï" };
   private String[] language = { "English", "Spanish", "French", "Arabic",
         "Hindi", "Greek" };

   public HelloWorld1(String countryLang) {
      this.countryLang = countryLang;
   }

   public String toString() {
      if (countryLang.equalsIgnoreCase(language[0]))
         return hellowWorldArray[0];
      else if (countryLang.equalsIgnoreCase(language[1]))
         return hellowWorldArray[1];
      else if (countryLang.equalsIgnoreCase(language[2]))
         return hellowWorldArray[2];
      else if (countryLang.equalsIgnoreCase(language[3]))
         return hellowWorldArray[3];
      else if (countryLang.equalsIgnoreCase(language[4]))
         return hellowWorldArray[4];
      else if (countryLang.equalsIgnoreCase(language[5]))
         return hellowWorldArray[5];
      else
         return "nothing found";
   }
}

Here is a class contain two array and one of them holds "hello world" in different language and other holds language name; another is a string variable named countryLan holds the language Name specified with the users;
and here is method name toString who is responsible for returning the Helloworld for the specified language;

Now lets write a another class named HelloWorldContstructor whose works is to consctruct Hello world;

Code:
package com.rokon;

public class HelloWorldContstructor {
   private HelloWorld1 theHeloWorld;

   public HelloWorldContstructor(String conLen) {
      theHeloWorld = new HelloWorld1(conLen);
   }

   public String toString() {
      return theHeloWorld.toString();
   }
}

Here we initialise the Helloword1 as theHelloworld and inject its value using constructor;


Now we'll write our main class. I named it HelloWorldMain;

Code:
package com.rokon;

public class HelloWorldMain {
   public static void main(String[] args) {
      try {
         HelloWorldContstructor tHWC = new HelloWorldContstructor(args[0]);
      } catch (ArrayIndexOutOfBoundsException e) {
         e.printStackTrace();
      }
   }
}



Here is main method. now If we run this program and wirte arabic in command Line.. it will print مرحبا العالم ;

Nice Jokes... to write simple Hello world we need 55 line code in object oriented desingn... ;
where we can write simple Hello World program in C with simple 4 line coding .. lets see some other Hello World program with various programming language;


In C
#include
int main(void) {
puts("Hello, World!");
}


In C++
#include
int main(void) {
std::cout << "Hello, World!\n";
}

In python and perl

print "Hello, World!"

In ruby
puts "Hello, World!"



Okay now We will see the loose coupling of java I mean object oriented design;
I know we everybody are very much familer on this because we already know the
spring framework ..;

Loose couping is a designing issue. Couping issuse comes when an object is dependent on others;
When an obeject cant work without another, we will say that they are tightly coupled;
But when two object can work independently, we will refer them loose coupled. More precisely, for say, A object is dependent on B. But somehow B become changed., so We need to change the A. But if the system is loose coupled then there is no need to change A. It will continue to work without modification.

Now see the example -
Code:
package com.rokon.loosecoupling;

public class Message {
   private String message;

   Message(String message) {
      this.message = message;
   }

   public void pirnt(Printer printer) {
      printer.print(this);
   }

   public String toString() {
      return message;
   }
}

Code:
package com.rokon.loosecoupling;

public interface Printer {
   void print(Message message);
}

Code:

package com.rokon.loosecoupling;

public abstract class AbstractPrinterFactory {
   public static AbstractPrinterFactory getFactory() {
      return new SystemOutPrinterFactory();
   }

   public abstract Printer getPrinter();
}

Code:
package com.rokon.loosecoupling;

public class SystemOutPrinterFactory extends AbstractPrinterFactory {
   public Printer getPrinter() {
      return new SystemOutPrinter();
   }
}


Code:
package com.rokon.loosecoupling;

public class HelloWorld {
   public static void main(String[] args) {
      Message message = new Message("Hello World");
      AbstractPrinterFactory factory = SystemOutPrinterFactory.getFactory();
      Printer printer = factory.getPrinter();
      message.pirnt(printer);
   }
}


and if you run it, output remain same as before and that is "Hello World";

if you need source code CLICK HERE

For more about it, I suggest you to google it. Im very much sure you'll enjoy tons of information about OOD of java..

Cheers


Last edited by bit0112-rokon on Sun Apr 04, 2010 10:44 am; edited 4 times in total (Reason for editing : TLD used)

_________________________________________________________________


Code Explosion Blog | Code Explosion Wiki | The Rokonoid | নির্ঝরিণী

BIT0112-Rokon
Programmer
Programmer

Course(s):
  • BIT

Blood Group: O+
Posts: 673
Points: 1269

View user profile http://blog.codexplo.org

Back to top Go down

Re: Great JOKES: JAVA OO design

Post by BIT0105-kanak on Sun Apr 04, 2010 10:57 am

valo laglo.

BIT0105-kanak
Alpha Release
Alpha Release

Posts: 46
Points: 68

View user profile http://mitaly.webs.com

Back to top Go down

Re: Great JOKES: JAVA OO design

Post by BIT0122-Amit on Sun Apr 04, 2010 1:01 pm

babago Neutral

_________________________________________________________________
Adminship / Moderatorship is not about power, it is about Responsibility.

|About me|My Blog|

BIT0122-Amit
Founder
Founder

Course(s):
  • BIT

Blood Group: O+
Posts: 4187
Points: 6601

View user profile http://iitdu.forumsmotion.com

Back to top Go down

Re: Great JOKES: JAVA OO design

Post by BIT0112-Rokon on Mon Apr 05, 2010 7:16 am

Kanak ki valo lagce..? java'r object oriented design..?

_________________________________________________________________


Code Explosion Blog | Code Explosion Wiki | The Rokonoid | নির্ঝরিণী

BIT0112-Rokon
Programmer
Programmer

Course(s):
  • BIT

Blood Group: O+
Posts: 673
Points: 1269

View user profile http://blog.codexplo.org

Back to top Go down

View previous topic View next topic Back to top


Permissions in this forum:
You cannot reply to topics in this forum