My Slider

Image Slider By Humayoun Kabir Lets Express our emotion with blog Email me at humayounk@ymail.com #htmlcaption

বৃহস্পতিবার, ২৬ ফেব্রুয়ারি, ২০১৫

জাভা কাস্টম ইভেন্ট হ্যান্ডেলিং বা ম্যানেজমেন্ট

প্রিয় বন্ধুরা , তোমরা সবাই কেমন আছ ? অনেক দিন পর ফিরে এলাম তোমাদের মাঝে । চাকুরীর ব্যস্ততার কারনে চাইলেও পোস্ট করতে পারি না । যাক কথা বাড়িয়ে লাভ নেই । আজকে আমরা দেখবো কিভাবে জাভা কাস্টম ইভেন্ট হেন্ডেল করতে হয় । প্রথমেই বলে নেই ইভেন্ট কি ? ইভেন্ট হল এক ধরনের একশন ( ফাংশন ) যা কোন অবজেক্ট ফাংশন কল করলে বা জাভা কম্পোনেন্ট গুলোর ফাংশনালিটি বুঝায় । যেমন কোন বাটন ক্লিক করলে , ড্রপডাউন পরিবর্তন করলে ইত্যাদি ... । এখানে বাটন , ড্রপডাউন ... হলো কম্পোনেন্ট আর ক্লিক হলো ইভেন্ট । আজকে আমরা যে কাজ করবো এটা কোন কম্পোনেন্ট ইভেন্ট প্রোগ্রামিং নয় বরং অবজেক্ট ভিত্তিক কাস্টম ইভেন্ট প্রোগ্রামিং । তো শুরু করা যাক , প্রথমেই আমরা বুধি আমরা কি করতে চাই । মনে করি আমাদের একটি অফিস রুম আছে সেই রুমে সবাই কে কার্ড পাঞ্চ করে ঢুকতে এবং বের হতে হয় । তো কার্ড পাঞ্চ করলে কি হবে ? কার্ড পাঞ্চ করার ফলে আমরা বুঝবো অফিস রুমে কতজন উপস্থিত এবং কে কে উপস্থিত । তো ধরুন পাঞ্চ মেশিন টা অনেক গুলো ফাংশন ইনপুট নেয় এবং কিছু ফাংশন আউটপুট হিসাবে দেয় যা অন্য ডিভাইস দিয়ে কাজে লাগাতে হয় । আমাদের কাজের সুবিধার্তে মনে করি পাঞ্চ মেশিন শুধু ইনপুট নিচ্ছে কয়জন পাঞ্চ করলো রুমে , এন্ট্রি এবং এক্সিট করার ক্ষেত্রে । তারপর আউট পুট হিসাবে জানাবে কয়জন রুমে উপস্থিত আছে । তো এই পাঞ্চ মেশিন যে ফাংশন লাইব্রেরী ব্যবহার করবে সেটাই আমরা আজ বানাবো জাভা দিয়ে । প্রকৃত পক্ষে এটাই ব্যবহার করে বা করবে তা নয় এটা একটা জাস্ট উদাহরন আর কিছুই না । তো শুরু করলাম নাকি ?...... প্রথমেই রুমে কারা ঢুকছে আর বের হচ্ছে এটা যেহেতু আমরা বের করতে চাচ্ছি তো প্রথমেই আমাদের রুম নামে একটা ক্লাস বানানো দরকার , ক্লাস কি ? ক্লাস হলো অবজেক্টের ব্লু প্রিন্ট । মনে করুন গাড়ী কোম্পানী গাড়ী বানাবে তো তারা হরেক মডেলের গাড়ী বানায় কিন্তু গাড়ীর কমন জিনিস গুলো যেমন গাড়ীর বডি , চার চাকা এগুলো তো একই থাকে তাই গাড়ির যে ব্লু প্রিন্ট তা তো এক তাই এখানে গাড়ির ক্লাস একটাই হবে । যাই হোক , তো আমাদের রুমের ক্লাস টা হবে এই রকম , রুম ক্লাসে কি কি আছে ? কয়জন রুমে আছে এটা বের করতে ব্যবহার করা হয়েছে কাউন্টার , রুম ইভেন্ট ফায়ার করে কাকে নটিফাই করবে তার জনা আছে লিসেনার যোগ করার ব্যবস্থা , কেউ রুমে প্রবেশ করলো কি না , নাকি বের হলো তার জন্য দুটি ফাংশন , আর ফায়ারিং ইভেন্ট টা । ইভেন্ট যখন ফায়ার হয় লিসেনার তখন লিসেন করে existenceReceive ফাংশন কল করে । তো আমরা ঝটপট এখন লিসেনার ইন্টারফেস টা বানিয়ে ফেলি , তো আমরা ইন্টারফেস কেন ব্যবহার করছি ? কারন হলো আমাদের মাল্টিপল লিসেনার থাকতে পারে যারা লিসেনারের একই ফাংশনালিটিগুলো ইউজ করতে পারে , অতিরিক্ত তাদের নিজস্ব কিছু ফাংশনালিটি থাকতে পারে , এছাড়া ফাংশন কল করার সময় অবজেক্ট পলিমরফিজম ইউজ করার জন্য , অর্থাৎ ইন্টারফেসের মাধ্যমে ইমপ্লিমেন্টেশন ক্লাস এর ফাংশন কল হবে । যাই হোক অনেক কমপ্লেক্স লেভেলের কথা বার্তা , এখনই যে সব বুঝতে পারবেন তা না তবে ধীরে ধীরে সব বুঝতে পারবেন । এখন তাহলে দেখি ExistenceListener অর্থাৎ লিসেনার এর কোড ,

package com.test.javacode;

public interface ExistenceListener {

 void existenceReceive(ExistenceEvent existEvent);

}

লিসেনার সব সময় প্যারামিটার হিসাবে ইভেন্ট গ্রহন করবে আর ইভেন্ট ক্লাস প্রপার্টি হিসাবে থাকবে যা যা আমি লিসেনারকে গ্রহন করাতে চাই , এখানে ইভেন্ট প্যারামিটার হলো ExistenceEvent , চলুন দেখি ExistenceEvent এর কোড ,

package com.test.javacode;

import java.util.EventObject;

public class ExistenceEvent extends EventObject {
 
 private static final long serialVersionUID = 1L;
 
 private Existence existence;
 private int countPersonInRoom;

 public ExistenceEvent(Object source, Existence existence, int countPersonInRoom) {
  super(source);
  this.existence = existence;
  this.countPersonInRoom = countPersonInRoom;
  
 }
 
 
 public Existence getExistence()
 {
  return existence;
 }
 
 public int getCountPersonInRoom()
 {
  return countPersonInRoom;
 }
 
 

}



এখানে Existence ক্লাস টা হলো কন্সট্যান্স ক্লাস যা থেকে আমরা কোন ব্যক্তি রুমে ঢুকেছে না বের হয়েছে তা সিগ্নাল ভ্যালু নিব । তো দেখা যাক Existence ক্লাসের কোড ,


package com.test.javacode;

public class Existence {
 
 public static final Existence ENTRY = new Existence("Entry");
 public static final Existence OUT = new Existence("Out");
 
 String existence;

 public Existence(String existence) {
  this.existence = existence;
 }

}



এখন আমরা একটা লিসেনার ক্লাস হিসাবে এডমিন ক্লাস নিবো যেটাতে ExistenceListener ইন্টারফেসের ইমপ্লিমেন্টেশন আছে ,



package com.test.javacode;

public class Admin implements ExistenceListener {

 @SuppressWarnings("unused")
 @Override
 public void existenceReceive(ExistenceEvent existEvent) {
  
   int totalPersonInRoom = existEvent.getCountPersonInRoom();
   String wordOfPersonForEntry = totalPersonInRoom > 1 ? " Persons have" : " Person has";
   String wordOfPersonForOut = totalPersonInRoom > 1 ? " Persons are" : " Person is";
   
  if(totalPersonInRoom > -1)
  {
   if(existEvent.getExistence() == Existence.ENTRY){
    System.out.println(totalPersonInRoom + wordOfPersonForEntry + " enter the room");
   }
   else if(existEvent.getExistence() == Existence.OUT){
    System.out.println(totalPersonInRoom + wordOfPersonForOut + "  now in the room");
   }   
  }
  else
  {
   System.out.println("No one is in room now !!");
  }
  
 }

}




ফাইনালি আমাদের কোড কে মেইন ফাংশনে টেস্ট করার পালা , তো করে ফেলি কি বলো ?


package com.test.javacode;

public class ADayInProgram {

 /**
  * @param args
  */
 public static void main(String[] args) {

        //I will have a object that notify when someone enters in a room or leave from room
        
        Room room = new Room();
        
        ExistenceListener listener = new Admin();
        
        room.addExistenceListener(listener);
        
        room.enterSomeOne();
        
        room.enterSomeOne();
        
        room.enterSomeOne();
        
        room.enterSomeOne();
        
        room.leaveSomeOne();
        
        room.leaveSomeOne();
        
        
        
 }

}

এই হলো আমাদের আউটপুট । ভাল থেকো সবাই আর আমার জন্য দুয়া রেখ । আবার আসবো ইনশাল্লাহ কোন একদিন অন্য কোন আর্টিকেল নিয়ে ।

বুধবার, ৪ ডিসেম্বর, ২০১৩

Regular Expression Shorcut Tutorial

Today I am going to write a tutorial on Regular Expression which is needed in daily basis of our programming life. And some of friends will agree with me that it can make us a little bit of trouble. But nothing to worry my dear friends . Here is the shortcut which i used in my programming life. If you don't like it please don't mind on me because i am not  a good blogger !!

RegExp has exec and test method

string has match,replace,search,split method for regular expression


var re = /ab+c/;  // You can call this way to initialize regular expression pattern

var re = new RegExp("ab+c"); // more standard when you not know the pattern [This is construct way]

/a*/ matches aaaaaaaa o or more times

but /a\*/ matches only a*

/a\b/ matches a with boundary word.
^ matches beginning of  input like as /^a/ matches in "a teddy bear" but not "A in E"

/ (foo) (bar) \1 \2/  // matches and remember first two words these called capturing parenthesis

/ (?:foo){1,2}/  non capturing parenthesis but not foo in "foo foo" but o in "foo"

x(?=y) match only if x is followed by y this is called look ahead

/ Jack (?=Frost|Sprat) / matches only jack followed by Frost or Jack Sprat.

x(?!y) match only if x is not followed by y negated look ahead
example : /\d+(?!\.)/ that matches "141" but not "3.141"

x|y matches either x or y
example : /green|red/ matches either in "green apple" or "red apple"

{n} matches exactly n occurrence of the preceding character
example : /a{2}/ matches in "caandy" but not in "candy"

{n,m} matches at least n and at most m occurrence of the preceding character
example : /a{1,2}/ matches 1 for in "Candy" , 2 for in "Caandy" , 3 for "Caaandy" and also in "Caaaaaaaaandy" because its matches preceding 3a like aaa

[xyz] matches any of the characters in brackets , this is same as [x-z]
example : [abcd] matches the 'b' in "brisket" and the 'c' in "city". The patterns /[a-z.]+/ and /[\w.]+/ match the entire string "test.i.ng".

[^xyz]  it matches anything that is not enclosed in the brackets
example: [^a-c] matches r in "briefcase"

[\b] matches a backspaces

\b matches a word boundary example: /\bm/ matches the m in "moon" , but  /\boo/ does not matches oo in "moon" because oo is followed by n , /oon\b/ matches in "moon" because oon is the end of word boundary.

\d matches a digit character equivalent to [0-9]

\s matches a single white space character example: /\s\w*/ matches bar  in "foo bar".

\w matches a alpha numeric character including the underscore equivalent to [A-Za-z0-9_]


Example with JavaScript (how to implement)

var myReg = /a(m+)i/g;
var myArray = myReg.exec("programming");
 
// Or this way If you want to construct the regular expression from a string 

var myReg = new RegExp("a(m+)i", "g");
var myArray = myRe.exec("programming");

সোমবার, ১০ জুন, ২০১৩

Create and Play Snake game with HTML5 and Jquery

Hello Friends,
Are you feeling boring today and want to play some game.What about if you play a game that was made be you !!! And it is made with only html5 and Jquery Then how about this ha.... (Really !!! Is it possible  !!! ) absolutely why not . So get ready, today i will share a full source code with you. Just copy and paste it on plain notepad and save as [any name].html (format). After saving just open this *.html file with recent browser that support html5. don't worry recent all browser support html5. And most importantly you need latest jquery version to download.Click here to download latest jquery.So why we waiting for....

Here is the  html source code below : (Just copy and Paste it)

<!DOCTYPE HTML>
<html>
<head>
  <title>Simple Snake Game with Html5 </title>
<script type="text/javascript" src="jquery-1.10.1.min.js" ></script>
<script type="text/javascript">
$(document).ready(function(){
    //Canvas stuff
    var canvas = $("#canvas")[0];
    var ctx = canvas.getContext("2d");
    var w = $("#canvas").width();
    var h = $("#canvas").height();
   
    //Lets save the cell width in a variable for easy control
    var cw = 10;
    var d;
    var food;
    var score;
   
    //Lets create the snake now
    var snake_array; //an array of cells to make up the snake
   
    function init()
    {
        d = "right"; //default direction
        create_snake();
        create_food(); //Now we can see the food particle
        //finally lets display the score
        score = 0;
       
        //Lets move the snake now using a timer which will trigger the paint function
        //every 60ms
        if(typeof game_loop != "undefined") clearInterval(game_loop);
        game_loop = setInterval(paint, 60);
    }
    init();
   
    function create_snake()
    {
        var length = 5; //Length of the snake
        snake_array = []; //Empty array to start with
        for(var i = length-1; i>=0; i--)
        {
            //This will create a horizontal snake starting from the top left
            snake_array.push({x: i, y:0});
        }
    }
   
    //Lets create the food now
    function create_food()
    {
        food = {
            x: Math.round(Math.random()*(w-cw)/cw),
            y: Math.round(Math.random()*(h-cw)/cw),
        };
        //This will create a cell with x/y between 0-44
        //Because there are 45(450/10) positions accross the rows and columns
    }
   
    //Lets paint the snake now
    function paint()
    {
        //To avoid the snake trail we need to paint the BG on every frame
        //Lets paint the canvas now
        ctx.fillStyle = "white";
        ctx.fillRect(0, 0, w, h);
        ctx.strokeStyle = "black";
        ctx.strokeRect(0, 0, w, h);
       
        //The movement code for the snake to come here.
        //The logic is simple
        //Pop out the tail cell and place it infront of the head cell
        var nx = snake_array[0].x;
        var ny = snake_array[0].y;
        //These were the position of the head cell.
        //We will increment it to get the new head position
        //Lets add proper direction based movement now
        if(d == "right") nx++;
        else if(d == "left") nx--;
        else if(d == "up") ny--;
        else if(d == "down") ny++;
       
        //Lets add the game over clauses now
        //This will restart the game if the snake hits the wall
        //Lets add the code for body collision
        //Now if the head of the snake bumps into its body, the game will restart
        if(nx == -1 || nx == w/cw || ny == -1 || ny == h/cw || check_collision(nx, ny, snake_array))
        {
            //restart game
            init();
            //Lets organize the code a bit now.
            return;
        }
       
        //Lets write the code to make the snake eat the food
        //The logic is simple
        //If the new head position matches with that of the food,
        //Create a new head instead of moving the tail
        if(nx == food.x && ny == food.y)
        {
            var tail = {x: nx, y: ny};
            score++;
            //Create new food
            create_food();
        }
        else
        {
            var tail = snake_array.pop(); //pops out the last cell
            tail.x = nx; tail.y = ny;
        }
        //The snake can now eat the food.
       
        snake_array.unshift(tail); //puts back the tail as the first cell
       
        for(var i = 0; i < snake_array.length; i++)
        {
            var c = snake_array[i];
            //Lets paint 10px wide cells
            paint_cell(c.x, c.y);
        }
       
        //Lets paint the food
        paint_cell(food.x, food.y);
        //Lets paint the score
        var score_text = "Score: " + score;
        ctx.fillText(score_text, 5, h-5);
    }
   
    //Lets first create a generic function to paint cells
    function paint_cell(x, y)
    {
        ctx.fillStyle = "blue";
        ctx.fillRect(x*cw, y*cw, cw, cw);
        ctx.strokeStyle = "white";
        ctx.strokeRect(x*cw, y*cw, cw, cw);
    }
   
    function check_collision(x, y, array)
    {
        //This function will check if the provided x/y coordinates exist
        //in an array of cells or not
        for(var i = 0; i < array.length; i++)
        {
            if(array[i].x == x && array[i].y == y)
             return true;
        }
        return false;
    }
   
    //Lets add the keyboard controls now
    $(document).keydown(function(e){
        var key = e.which;
        //We will add another clause to prevent reverse gear
        if(key == "37" && d != "right") d = "left";
        else if(key == "38" && d != "down") d = "up";
        else if(key == "39" && d != "left") d = "right";
        else if(key == "40" && d != "up") d = "down";
        //The snake is now keyboard controllable
    })
   
})
</script>
</head>
<body>

<!-- Lets make a simple snake game -->
<canvas id="canvas" width="450" height="450"></canvas>


</body>
</html>

Facebook Tricks with Javascript



1. Select all Friends for an Invitation instantly
You can select all friends easyli just open any page or group click on suggest or invite and copy this code and paste in the url box. and hit Enter....thats it
javascript:elms=document.getElementById('friends').getElementsByTagName('li');for(var fid in elms){if(typeof elms[fid] === 'object'){fs.click(elms[fid]);}}
2. View the Hidden content of a page without making a Like
This trick is used to view the hidden content of any Facebook page without making a like to that page. This trick was also previous published in our recent post  How to view the hidden content of Facebook pages without making a Like, you can find even more tricks related to this topic in this post.
javascript:(function(){for(var%20t=document.getElementsByTagName("*"),l=t.length;l--;){t[l].style.visibility=""}}())
3. View Private Photos on Facebook
This trick is used to view the photos of people blocked due to privacy issue even without adding them on Facebook. Just go to the person’s page and enter the following code in the address bar. Now as soon as you hit the Enter key, the private photos are unveiled to you now.
javascript:(function(){CSS.removeClass(document.body,%20'profile_two_columns');
tab_controller.changePage("photos");})()
4.Edit any page
Javascript:document.body.contentEditable=”true”;document.designMode=”true”;void 0

I hope this will help to make some fun!! any feedback mail me : humayounk@ymail.com

সোমবার, ২২ অক্টোবর, ২০১২

C# Repository Pattern Example

First Of all I Would Like to mention The following content is not mine it's my mentor Redmond sir content. I just  use his content to present towards you to get an idea what is Repository pattern .The Repository Pattern is a pattern that is being used in software architecture  in  recent times. So you have to  understand what is this pattern about.

The Repository Pattern is a common construct to avoid duplication of data access logic throughout our application. This includes direct access to a database, ORM, WCF dataservices, xml files and so on. The sole purpose of the repository is to hide the nitty gritty details of accessing the data. We can easily query the repository for data objects, without having to know how to provide things like a connection string. The repository behaves like a freely available in-memory data collection to which we can add, delete and update objects.
The Repository pattern adds a separation layer between the data and domain layers of an application. It also makes the data access parts of an application better testable.
The example below show an interface of a generic repository of type T, which is a LINQ to SQL entity. It provides a basic interface with operations like Insert, Delete, GetById and GetAll. The SearchFor operation takes a lambda expression predicate to query for a specific entity.

The implementation of the IRepository interface is pretty straight forward. In the constructor we retrieve the repository entity by calling the datacontext GetTable(of type T) method. The resulting Table(of type T) is the entity table we work with in the rest of the class methods. e.g. SearchFor() simply calls the Where operator on the table with the predicate provided.
The generic GetById() method explicitly needs all our entities to implement the IEntity interface. This is because we need them to provide us with an Id property to make our generic search for a specific Id possible.

Since we already have LINQ to SQL entities with an Id property, declaring the IEntity interface is sufficient. Since these are partial classes, they will not be overridden by LINQ to SQL code generation tools.

We are now ready to use the generic repository in an application.

Once we get of the generic path into more entity specific operations we can create an implementation for that entity based on the generic version. In the example below we construct a HotelRepository with an entity specific GetHotelsByCity() method. You get the idea. ;-)

The code below shows a nice and clean implementation of the generic repository pattern for the Entity Framework. There’s no need for the IEntity interface here since we use the convenient Find extension method of the DbSet class. 


সোমবার, ২৭ আগস্ট, ২০১২

Singleton Design Pattern in C#

Singleton Design Pattern

Intent


  • Ensure a class has only one instance, and provide a global point of access to it.
  • Encapsulated “just-in-time initialization” or “initialization on first use”.

Problem


Application needs one, and only one, instance of an object. Additionally, lazy initialization and global access are necessary.

Discussion


Make the class of the single instance object responsible for creation, initialization, access, and enforcement. Declare the instance as a private static data member. Provide a public static member function that encapsulates all initialization code, and provides access to the instance.

The client calls the accessor function (using the class name and scope resolution operator) whenever a reference to the single instance is required.

Singleton should be considered only if all three of the following criteria are satisfied:

  • Ownership of the single instance cannot be reasonably assigned
  • Lazy initialization is desirable
  • Global access is not otherwise provided for

If ownership of the single instance, when and how initialization occurs, and global access are not issues, Singleton is not sufficiently interesting.

The Singleton pattern can be extended to support access to an application-specific number of instances.

The “static member function accessor” approach will not support subclassing of the Singleton class. If subclassing is desired, refer to the discussion in the book.

Deleting a Singleton class/instance is a non-trivial design problem. See “To Kill A Singleton” by John Vlissides for a discussion.

Structure

Scheme of Singleton


Make the class of the single instance responsible for access and “initialization on first use”. The single instance is a private static attribute. The accessor function is a public static method.

Scheme of Singleton.

Example


The Singleton pattern ensures that a class has only one instance and provides a global point of access to that instance. It is named after the singleton set, which is defined to be a set containing one element. The office of the President of the United States is a Singleton. The United States Constitution specifies the means by which a president is elected, limits the term of office, and defines the order of succession. As a result, there can be at most one active president at any given time. Regardless of the personal identity of the active president, the title, “The President of the United States” is a global point of access that identifies the person in the office.

Example of Singleton.

Check list


  1. Define a private static attribute in the “single instance” class.
  2. Define a public static accessor function in the class.
  3. Do “lazy initialization” (creation on first use) in the accessor function.
  4. Define all constructors to be protected or private.
  5. Clients may only use the accessor function to manipulate the Singleton.

Rules of thumb


  • Abstract Factory, Builder, and Prototype can use Singleton in their implementation.
  • Facade objects are often Singletons because only one Facade object is required.
  • State objects are often Singletons.
  • The advantage of Singleton over global variables is that you are absolutely sure of the number of instances when you use Singleton, and, you can change your mind and manage any number of instances.
  • The Singleton design pattern is one of the most inappropriately used patterns. Singletons are intended to be used when a class must have exactly one instance, no more, no less. Designers frequently use Singletons in a misguided attempt to replace global variables. A Singleton is, for intents and purposes, a global variable. The Singleton does not do away with the global; it merely renames it.
  • When is Singleton unnecessary? Short answer: most of the time. Long answer: when it’s simpler to pass an object resource as a reference to the objects that need it, rather than letting objects access the resource globally. The real problem with Singletons is that they give you such a good excuse not to think carefully about the appropriate visibility of an object. Finding the right balance of exposure and protection for an object is critical for maintaining flexibility.
  • Our group had a bad habit of using global data, so I did a study group on Singleton. The next thing I know Singletons appeared everywhere and none of the problems related to global data went away. The answer to the global data question is not, “Make it a Singleton.” The answer is, “Why in the hell are you using global data?” Changing the name doesn’t change the problem. In fact, it may make it worse because it gives you the opportunity to say, “Well I’m not doing that, I’m doing this” – even though this and that are the same thing.

 

Ensures a class has only one instance and provide a global point of access to it.

This structural code demonstrates the Singleton pattern which assures only a single instance (the singleton) of the class can be created.

using System;

  class MainApp
  {
 
    static void Main()
    {
      // Constructor is protected -- cannot use new 
      Singleton s1 = Singleton.Instance();
      Singleton s2 = Singleton.Instance();

      if (s1 == s2)
      {
        Console.WriteLine("Objects are the same instance");
      }

      // Wait for user 
      Console.Read();
    }
  }

  // "Singleton" 
  class Singleton
  {
    private static Singleton instance;

    // Note: Constructor is 'protected' 
    protected Singleton() 
    {
    }

    public static Singleton Instance()
    {
      // Use 'Lazy initialization' 
      if (instance == null)
      {
        instance = new Singleton();
      }

      return instance;
    }
  }
}

Why Design Patterns and How to Implement in C#(Part-1)

Design Patterns

In software engineering, a design pattern is a general repeatable solution to a commonly occurring problem in software design. A design pattern isn't a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that can be used in many different situations.

Uses of Design Patterns

Design patterns can speed up the development process by providing tested, proven development paradigms. Effective software design requires considering issues that may not become visible until later in the implementation. Reusing design patterns helps to prevent subtle issues that can cause major problems and improves code readability for coders and architects familiar with the patterns.
Often, people only understand how to apply certain software design techniques to certain problems. These techniques are difficult to apply to a broader range of problems. Design patterns provide general solutions, documented in a format that doesn't require specifics tied to a particular problem.
In addition, patterns allow developers to communicate using well-known, well understood names for software interactions. Common design patterns can be improved over time, making them more robust than ad-hoc designs.

Creational design patterns

This design patterns is all about class instantiation. This pattern can be further divided into class-creation patterns and object-creational patterns. While class-creation patterns use inheritance effectively in the instantiation process, object-creation patterns use delegation effectively to get the job done.
  • Abstract Factory
    Creates an instance of several families of classes
  • Builder
    Separates object construction from its representation
  • Factory Method
    Creates an instance of several derived classes
  • Object Pool
    Avoid expensive acquisition and release of resources by recycling objects that are no longer in use
  • Prototype
    A fully initialized instance to be copied or cloned
  • Singleton
    A class of which only a single instance can exist

Structural design patterns

This design patterns is all about Class and Object composition. Structural class-creation patterns use inheritance to compose interfaces. Structural object-patterns define ways to compose objects to obtain new functionality.
  • Adapter
    Match interfaces of different classes
  • Bridge
    Separates an object’s interface from its implementation
  • Composite
    A tree structure of simple and composite objects
  • Decorator
    Add responsibilities to objects dynamically
  • Facade
    A single class that represents an entire subsystem
  • Flyweight
    A fine-grained instance used for efficient sharing
  • Private Class Data
    Restricts accessor/mutator access
  • Proxy
    An object representing another object

Behavioral design patterns

This design patterns is all about Class's objects communication. Behavioral patterns are those patterns that are most specifically concerned with communication between objects.
  • Chain of responsibility
    A way of passing a request between a chain of objects
  • Command
    Encapsulate a command request as an object
  • Interpreter
    A way to include language elements in a program
  • Iterator
    Sequentially access the elements of a collection
  • Mediator
    Defines simplified communication between classes
  • Memento
    Capture and restore an object's internal state
  • Null Object
    Designed to act as a default value of an object
  • Observer
    A way of notifying change to a number of classes
  • State
    Alter an object's behavior when its state changes
  • Strategy
    Encapsulates an algorithm inside a class
  • Template method
    Defer the exact steps of an algorithm to a subclass
  • Visitor
    Defines a new operation to a class without change

Criticism

The concept of design patterns has been criticized by some in the field of computer science.

Targets the wrong problem

The need for patterns results from using computer languages or techniques with insufficient abstraction ability. Under ideal factoring, a concept should not be copied, but merely referenced. But if something is referenced instead of copied, then there is no "pattern" to label and catalog. Paul Graham writes in the essay Revenge of the Nerds.
Peter Norvig provides a similar argument. He demonstrates that 16 out of the 23 patterns in the Design Patterns book (which is primarily focused on C++) are simplified or eliminated (via direct language support) in Lisp or Dylan.

Lacks formal foundations

The study of design patterns has been excessively ad hoc, and some have argued that the concept sorely needs to be put on a more formal footing. At OOPSLA 1999, the Gang of Four were (with their full cooperation) subjected to a show trial, in which they were "charged" with numerous crimes against computer science. They were "convicted" by ⅔ of the "jurors" who attended the trial.

Leads to inefficient solutions

The idea of a design pattern is an attempt to standardize what are already accepted best practices. In principle this might appear to be beneficial, but in practice it often results in the unnecessary duplication of code. It is almost always a more efficient solution to use a well-factored implementation rather than a "just barely good enough" design pattern.

Does not differ significantly from other abstractions

Some authors allege that design patterns don't differ significantly from other forms of abstraction, and that the use of new terminology (borrowed from the architecture community) to describe existing phenomena in the field of programming is unnecessary. The Model-View-Controller paradigm is touted as an example of a "pattern" which predates the concept of "design patterns" by several years. It is further argued by some that the primary contribution of the Design Patterns community (and the Gang of Four book) was the use of Alexander's pattern language as a form of documentation; a practice which is often ignored in the literature.

 

শনিবার, ২৫ আগস্ট, ২০১২

জাভাস্ক্রিপ্ট টিউটরিয়াল (পর্ব-৩)

মাষ্টার্স পরীক্ষা আর ঈদের পর ফিরে এলাম আপনাদের মাঝে ।পোস্ট দিতে দেরি   হল বলে আন্তরিকভাবে দুঃখিত ।  আজ আমরা দেখবো কিভাবে এইচ টি এম এলের সাথে জাভাস্ক্রিপ্ট মানিক জোড়ের মত সম্পর্ক করে ডাইনামিক ওয়েব সাইট তৈরী করে । তাহলে দেখা যাক ,

HTML পেজে জাভামস্ক্রিপ্ট যুক্ত করার জন্য স্ক্রিপ্ট ট্যাগ ব্যবহার করা হয়।ঠিক এর অনুরূপে লেখা হয়।<script> </script>অংশের মধ্যে প্রয়োজনীয় এবং অন্যান্য কোড সমূহ রাখা হয়। অথবা এর মধ্যে জাভামস্ক্রিপ্ট যুক্ত করা হয়। হেডার এর মধ্যে রাখলে তাকে বলা হয় হেডার স্ক্রিপ্ট(header script) আর বডি এর মধ্যে করা হলে তাকে বলা হয় (body script) । সচরাচর এর মধ্যে বিভিন্ন ধরনের ফাংশন তৈরি করা হয় আর এর মধ্যে থেকেই  ঐ ফাংশনকে প্রয়োজনে কল করা হয়।
উদাহরনঃ
 <strong style="margin: 0px; padding: 0px; border: 0px; outline: none; color: rgb(0, 0, 0); ">www.amakeniye.blogspot.com</strong>

<html>
<head>



<title> www.amakeniye.blogspot.com
<
/title
>


<style>
body{background: #FFC}
</style>
<script type=”text/javascript”>
function myClick()
{
alert(“Welcome to JavaScript  World.”);
}

</script>
</head>
<body>

<button onclick=”myClick()”>Click Me
<
/button
>
</body>
</html>

একটা নোটপ্যাড open করে উপরের code টুকু লিখে file মেনু থেকে Save as এ ক্লিক করে File name: index.html , Save as type : All files, দিয়ে save করে index.html ফাইলটি আপনার পছন্দনীয় ব্রাউজার  দিয়ে open করলে নিচে প্রদর্শিত ছবির মত দেখাবে।
ব্লগে কোড অত্যন্ত ঝামেলার কাজ তাই কোড সঠিকভাবে বুঝা না গেলে আমি আন্তরিকভাবে দুঃখিত ।