Kasun’s Blog

December 25, 2008

Visitor Pattern

Filed under: Computer Science — kasun04 @ 5:16 am

In Object Oriented Design, the visitor patter is one of the obscure pattern yet powerful enough to solve many complex OO scenarios. Visitor Pattern is also not really easy to understand at the first glance but you need to dig it around with practical examples. (I guess it’s not just for Visitor pattern but also for all the other patterns)

I would like to give a clean and simple introduction to visitor pattern with this post. So let’s start with a simple example ofthe usage of Visitor pattern

Visitor Pattern is often useful when there are fair numbers of related classes. One of the common examples of such a scenario is ‘drawing different shapes’. In this case we have a set of related classes; Circle, Trangle, Rectangle etc.

Now, if we are going to implement a draw() function for all these classes i.e. circle::draw(), trangle::draw().. etc we may be drawing different shapes but we are replicating a fair amount of code in all the classes. (Because the underlying methods, that we use to draw a ’shape’ is similar)

Visitor pattern is quite capable of solving this kind of scenarios. Here what we are doing is that we port all the draw methods of each shaped inherited classes (Circle, triangle, Rectangle) to one common class called ‘DrawVisitor’ or simply ‘Visitor’. Then in the ‘DrawVisitor’ we have a set of functions overloads based on the type of object passed to it (Circle, Triangle, Rectangle etc), which implements the ‘drawing logic’. And its obvious that since we use a single visitor class to do the drawing of shapes we can share whatever the resources that we want to draw and can reuse drawing code.

There are a lot of concerns about using Visitor pattern, because applying visitor pattern to a given scenario often makes things ambiguous. However the applicability of

Visitor pattern is justified by James Cooper (author of a Java companion to the GoF) by giving us a real world scenario which is essentially solvable only from visitor pattern. His primary example :

Suppose you have a hierarchy of Employee-Senior Manager-Vendor etc. They all enjoy a normal vacation day accrual policy, but, Senior Manger also participates in a “bonus” vacation day program. As a result, the interface of class SeniorManager(as well as ‘Vendor’ and ‘SecurityOfficer’) is different than that of class Employee. We cannot polymorphically traverse a Composite-like organization and compute a total of the organization’s remaining vacation days. This is how we use the visitor pattern to solve this problem.

- Create a ‘VacationVisitor’ which handles all the vacation manipulations and implementing different vacation manipulations in polymorphic visitor methods.

- Each visited instance (Employee, SeniorManager etc) is implementing an ‘accept’ method which in turns call the polymorphic visitor method.

- This method call procedure is termed as ‘Double Dispatch’

dd

- The complete class design looks like this.

visi

“The Visitor becomes more useful when there are several classes with different interfaces and we want to encapsulate how we get data from these classes.”

There are several motivations to use the visitor pattern.

- Add functions to class libraries for which the source is unrevealed or simple source is unavailable

- Obtain data from a distinct collection of unrelated classes and use it to present the results of a global calculation to the user program

- Gather related operations into a single class rather than force you to change or derive classes to add these operations

- Collaborate with the Composite pattern

September 18, 2008

emacs rocks!

Filed under: Uncategorized — kasun04 @ 5:04 am

emacs with ecb!

September 7, 2008

Chrome, Firefox, Safari and Opera – CPU and Memory usage

Filed under: Uncategorized — kasun04 @ 9:24 am

I perfromed a CPU usage and Memory usage test on Google Chrome, Firefox, Apple Safari and Opera. I simply ignore IE7 because the real battle comes when IE8 is officially relesed.

Here are my results. (or proofs) as screen shots.

IDLE State

Same Tabs Opened (various site were selected. Gmail, Apple, BBC, Youtube vedio streaming)

So then,  we can analyze the resource usage.

Chrome vs Opera

This is another comparison between Opera and Chrome.

Bottom Line

You have to decide which browser to be used.

Search Engine Technology-An In depth Analysis (I)

Filed under: Uncategorized — kasun04 @ 8:16 am

A search engine is an information retrieval system (IR Systems-See my prior post) designed to help find information stored on a computer systems. Search engines minimize the time required to find information and the amount of information which must be consulted.

The search engine technology is evolved over the past decade or so, owing to the continuous and rapid grow of World Wide Web. As the information systems grow bigger and bigger the amount information stored in the information systems became enormous. So as an information retrieval system, the search engine has to be evolved in order to be sync. with the growing stored data.

The most public, visible form of a search engine is a Web search engine which searches for information on the World Wide Web. And more or less that the most important form of the search engine, because the www is the world’s fastest growing, distributed and fault tolerant information system. As an important business product the Enterprise Search Engines also play a critical role as most of the companies need to have their own customizable information retrieval system which is beyond a conventional web search engine.

Regardless of web or enterprise search, the technology used by the both forms are quite similar. in fact from the core (or heart) of the both engine looks almost the same. Here is a brief overview of different forms of Search Engines.

Web Search Engines

A Web search engine is a search engine designed to search for information on the World Wide Web. Information may consist of web pages, images and other types of files (including pdf, doc etc.). Web Search products are typically free to use and the vendors generate revenue via advertising.

Challenges:
  • The number of documents to be indexed (tens of billions)
  • The number of users (hundreds of millions)
Major Vendors:
  • Google
  • Microsoft
  • Yahoo

Enterprise search Engines

Enterprise search is the practice of identifying and enabling specific content across the enterprise to be indexed, searched, and displayed to authorized users. Enterprise Search Engine facilitates the application of search technology to information within an organization. And most of ES vendors tend to focus exclusively on Enterprise Search and do not also offer Web Search or Desktop Search products.

Challenges:
  • Index documents from a variety of sources such as: File systems, Intranets, Document Management Systems, E-mail, Databases.
  • Present a consolidated list of relevance ranked documents from these various sources
  • Many applications require the integration of structured data as part of the search criteria and when presenting results back to the users controls are vital
  • if users are to be restricted to documents to which they are granted access by the various document repositories within the enterprise
Major Vendors:
  • Microsoft (FAST Search & Transfer, Convera)
  • Autonomy
  • Dieselpoint
  • Endeca
  • Exalead
  • IBM
  • ORACLE
  • Google

Desktop search

Desktop search is about searching the documents personal to a single user (i.e. a local hard drive and email folders).Most of the leading Desktop Search products are provided as free downloads, or for a small fee per user.

Challenges:
  • To offer the search on the user’s local machine without impacting the performance of other applications running locally.
Vendors:
  • Microsoft
  • Google & Copernic/Coveo.

August 30, 2008

Fastest and Elegant Browser on Earth – Opera 9.52

Filed under: Computer Science — kasun04 @ 4:21 am

Opera 9.52 is considered to be as the most powerful web browser that offers number of utilitarian features without penalizing the performance. As its counter part, Mozilla Firefox becoming more and more famous among web users, Opera is also becoming one of the major competitors against Firefox. Although many people are used to boring and tiresome Firefox, Opera’s latest version came up with a bunch of awesome features.

Faster Rendering Engine – Presto Rendering Engine

Opera uses their very own rendering engine (layout engine); ‘Presto’. ‘Presto’ is much faster than the tedious
‘Gecko’ layout engine (Mozilla project’s layout engine).

Elegant Look

You should use it and experience it. Here are some screen captures.

Download Manager with BitTorrent

Download files quicker with Opera. Opera starts downloading as soon as you’ve saved the file, so there’s no wasted time. Pause and resume downloads with the push of a button, and choose multiple files to download simultaneously without any fuss. Opera also features built-in support for the social file distribution protocol, BitTorrent, which makes it easy to download Torrent files without the need for a separate application.
I guess you know this .. Firefox download manager sucks!!

Opera Link and Speed Dial

Access your favorite Web sites everywhere!. Opera link syncs your bookmarks and Speed Dial between your computers and mobile phone. See the screen shots to see the use of speed dial.
(Firefox and IE copied this from opera. )

Tabs and Sessions

Most comprehensive tab browsing was introduced by Opera. Opera is very light on your computer, so it’s possible to have many tabs open at once. Drag and drop tabs around to change their order, or get a preview pausing over them with your mouse. You can even save a session of tabs for later, making it easy to pick up where you left off.

Zoom and Fit to width

Is it difficult to read the content on a page? Use Opera’s Zoom button in the lower right corner to resize Web
pages. If the page is too wide for your screen, simply hit “Fit to Width” and Opera will resize the Web page so you avoid horizontal scrolling.

Built-in e-mail and newsfeeds

Opera’s built-in e-mail client features improved responsiveness. It also retrieves and searches your mail and news feeds even faster than before. In Opera, newsfeeds are stored on your computer so you can read them later, even when you’re offline. Easily tag articles so you know which ones you want to read, which ones are important, which ones are funny, etc.

Quick Find

Have you ever forgotten the page where you found that great article or that perfect gift? When using Opera the browser remembers not only the titles and addresses, but the actual content of the Web pages you visit.

Visit – http://www.opera.com/

August 24, 2008

Best IDE for Linux – Emacs Code Browser

Filed under: Uncategorized — kasun04 @ 2:46 pm

A C/C++ developer on Linux platform, is someone who always seeks for a IDE that suits his work, but ends up with using tedious ‘vim’ or unstable eclipse CDT or Netbeans C/C++.

But for me the most powerful IDE for C/C++ development in Linux platform is emacs. Using just only emacs would do a little but emacs gain enmourse power when it used with Emacs Code Browser (ECB).

This is almost an IDE that is enriched with all the possible features in the modern IDEs in Windows like VS or IntelliJ. Have a look :-) .

screenshot

August 22, 2008

Facebook is not just an addiction–it’s a disease

Filed under: Uncategorized — kasun04 @ 8:36 pm

If you are a dummy pc user, there is nothing to complain about using Facebook (and other such social networks) .. because you don’t have any other work to do with web or computer.

The problem arises if you are a IT Professional and still wasting time on Facebook. Here is a nice article that tells the true story.(I’m pasting it here :-) )

source: Collegiate Times, by Susan Mulla

These words will go down in history: “Susan Mulla has requested to add you as a friend, but before we can do that, you must confirm that you are, in fact, friends with Susan.” If you’re ever lucky enough to receive an email saying that phrase, you best accept my friendship. If you don’t, how else can we read each other’s profiles every five seconds, or write inside jokes on each other’s “walls”? I think we all know what I’m talking about here; it’s the Facebook <WWW.THEFACEBOOK.COM>, and it has changed the way we live as college students.

Some have said, “Facebook is the worst social disease to hit college campuses nationwide,” and I would have to agree with that statement. So let’s take a deeper look into this new fad that has taken so many of us captive.Being a member of this cult following, I’ve realized that quite possibly the most crucial aspect of the Facebook is creating a flawless profile. Many of us are guilty of spending hours upon hours crafting our profile to ensure we come across as desirable to that special someone stumbling upon it. A flattering picture is the first step to the perfect profile. Next, your music interests have to be listed, but in all honesty it’s just an opportunity for people to pretend they are really eclectic with their music tastes. For example one might write: “I’m totally into ‘Death Cab for Cutie,’ ‘The Pussycat Dolls’ and ‘Yo-Yo Ma.’” You don’t have to try to impress people by listing every band you’ve ever heard of — it’s pretty obvious you’re faking.

Then there is always the request for friendship from that old high school “friend” who you actually never said a word to in high school. Maybe it was the person who laughed in your face when you asked them to prom, and now expects you to accept their friendship. Heck no. I say reject that “friendship” and show them what they missed out on. Then, there’s that whole “poking” deal. I will never forget the first time I was “poked.” I just sat there at my computer dumbfounded, in awe of the words I saw in front of me: “You have been poked, do you want to poke back?” I wasn’t sure if I should be flattered, offended or violated.

There’s also that whole stalking thing, too. Let’s be honest. We can all admit that Facebook has opened a door to the opportunities to stalk people. For example — last year there was a guy in one of my classes who caught my eye, and being too scared to talk to him in person, I Facebooked him. About five minutes later I find myself sitting in my room listening to the mp3s I got off his AIM profile and flipping through his Web shots. What was I doing? I didn’t even know the guy and already he was serenading me.Now, I can’t help but ask myself what is going to come of us if we continue communicating via Facebook and Instant Messenger? Will we eventually meet people, start dating, get engaged, get married and have kids and get divorced, all in one chat session? I know it might seem like I’m sitting here pointing my finger at all of you, but I’m just as guilty of Facebook addiction and compulsive away message reading as the next screen name on your buddy list. To be completely honest, I haven’t yet met my Collegiate Times editor in person, because all we do is pass e-mail back and forth.

What killed normal human interaction? I think we have simply become lazy. It’s easier to put up an away message that will let people know if you’ve had a bad day or billboard every single detail of what your schedule entails for that day: “Off to class, then lunch, then the gym, then the bathroom, then washing my hands, then drying them.” Who needs to know all of that?

So here is what I say to you all of you who sit at your computers and check away messages and stalk the guy you saw at Hokie Grill once — stop living like this. I’m convinced that we could fritter our whole lives sitting in front of the computer screen. What we need to do is ask ourselves this question: “What will happen when all of my buddies are away, or when the Internet connection cuts short.” We need to face it and realize that life doesn’t happen on a computer screen, that having 202 friends on Facebook doesn’t make you cool.

Atif Aslam

Filed under: Music — kasun04 @ 7:32 pm

Atif Aslam is one of the youngest yet a powerful voice in the indian pop music feild. He got unique voice which is a blend of Indian and Pakistani vocices. Infact he originated in Wazirabad, Pakistan and finally became one of the most wanted background singer in Bollywood.

He has released sevaral albums under TIPS and Fire Records lables and they were quite successfull as his various singles released in latest movies like Race, Kismat Konnection etc.

He is well-known in the subcontinent and with ex-pats for his songs ‘Aadat’, ‘Hum Kis Gali Jaa Rahe hain’, ‘Ehsaas’, ‘Doorie’, ‘Kuch Is Tarah’, “Woh lamhe”, “Pehli nazar mein” and “Tere Bin”. He was formerly the lead singer of Jal.

If there is something that rellay impress many people around the world.. that is his voice.. Its not Hindi .. its not Urdu.. just listen to this..

Atif Aslam | Pehli nazar mein | race

July 27, 2008

How to stop popoing out the IE when AIM starts up.

Filed under: Computer Science — kasun04 @ 7:35 am

This is a problem that I was suffering for sevaral months.  Anyway i found a way to do so. Not that its hard to do but I guess people can’t find it.

Disable AIM Today or AIM Dashboard from popping up in Internet Explorer

  • Open Aim 6.5
  • Click Edit
  • Click Settings
  • Click Sign In / Sign Out
  • Click None
  • Click Save

Hope this helps :-)

Information retrieval (IR) Systems: Enterprise and Web Search

Filed under: Computer Science — kasun04 @ 5:44 am

I heard many people now tends to talk about a new era of computer and information technology called Information age (Some may call it Digital or Wireless age according to his preferences). So, It’s clear that in the

present world ‘information’ (digitally represented) becomes the master and we all relaying on it.

When it comes to information, gathering and storing information is almost done up to the perfection owing to modern development of computer science. But the ‘information retrieval’ is still a challenge to the ICT world.

The area of computer science dealing with searching and processing collections of multimedia documents is known as Information Retrieval (IR). The IR systems solve the effective storing and querying of textual (or multimedia) documents.

The systems can be used for web pages searching in the Internet or a specified collection of documents are often referring to as ‘Search Engines’.

More precisely “Googling” is more or less the most popular way of information retrieval mechanism from the world’s largest collection of multimedia and textual document collection; the World Wide Web. Apart from Google, there are several information retrieval systems yet to become famous like Yahoo, Live Search etc.

Web Search Engine are quite popular but the modern business models relying on much more customizable IR system that you can plug various different collections of data to the IR system. For example a company may want to use the web, a pre-defined set of documents and some other third part IR retrieval system to be used as the company data repository to the company IR system. This is where the ‘Enterprise Search Engines’ come in to play.

Currently world’s most famous and reputed Enterprise Search Platform is the FAST Search and Transfer (now owns by Microsoft Cooperation) which is able to beat the giant’s (Google’s) Enterprise Search Platform. By the way FAST do support crawling through the internet but as a web search engine FAST is no way near Google.

So, its clear that both Google and FAST are going on two different path while both of them are the predominant leaders in each streams (web & enterprise search).

Information Retrieval use various different technologies to store and retrieve information and web search and enterprise search uses different strategies in their own methodology.

« Previous PageNext Page »

Blog at WordPress.com.