KakimotOnline

September 30, 2008

Object-Oriented Design Heuristics

Filed under: software design — Tags: — nandokakimoto @ 12:14 am

Hi,

Object-Oriented Design Heuristics is the book I’ve been reading for the last two months. Besides of the amount of work in this period, I could always find some time to read it.  The book has 11 chapters and, without appendixes, 217 pages. So, it’s not a exhaustive reading.

The most interesting in this book is the fact that it address an issue that every programmer think he/she knows: object-oriented programming. I was one of them. I thougth that I knewn object-oriented programming and now I realized that this paradigm envolves more than I ever suspect.

The book offers insight into object-oriented improvement. The more than sixty guidelines presented are language-independent and allow you to rate the integrity of a software design. The heuristics are not written as hard and fast rules and cover important topics ranging classes and objects to physical object-oriented design.

As you might be curious about the heuristics, I will be nice and tell some of them:

  • Be sure the abstractions that you model are classes and not simply the roles object play: is Mother and Father a class, or the role that certain Person objects play? The answer depends on the domain that a designer is modeling. If, in the given domain, Mother and Father have different behavior, then they should probably be modeled as classes. If they have the same behavior, then they are different roles that object object of Person class play.
  • Do not create god classes/objects in you system. Be very suspicious of a class whose name contains Driver, Manager, System, or Subsystem: developers attempt to capture the central control mechanism prevalent in the action-oriented paradigm within their object-oriented design. The result is the creation of a god object that performs most of the work, leaving minor details to a collection of trivial classes.
  • A class must know what it contais, but it should not know who contains it: this heuristcs is important if a designer wishes to reuse his or her abstractions. Consider the relationship “BedRoom contais AlarmClock”. It is necessary that the BedRoom object knows about its contained AlarmClock object, but the AlarmClock should have no dependencies on the BedRoom. The main reason is reusability. I want to use the AlarmClock out of the BedRoom in the future. If the AlarmClock is dependent on the BedRoom, then the BedRoom goes wherever the AlarmClock goes.
  • If you have an example of multiple inheritance in your design, assume you have made a mistake and then prove otherwise: this heuristics is meant to emphasize the large level  of multiple inheritance misuse that existis in many object-oriented designs. So, assume that there is a mistake first.

Well, it’s good for now. If you like the advices, there are a lot more inside the book.

See you,


Fernando

September 16, 2008

Ajax Control Toolkit

Filed under: ASP.NET, ajax — Tags: — nandokakimoto @ 2:46 am

Hi,

today will talk about a really useful web development library, called the Ajax Control Toolkit.

“The AJAX Control Toolkit is a joint project between the community and Microsoft. Built upon the ASP.NET 2.0 AJAX Extensions, the Toolkit aims to be the biggest and best collection of web-client components available. The Toolkit addresses three needs. First it gives website developers a place to get components to make their web applications spring to life, second it gives a set of great examples for those wishing to write client-side code, and third it is a place for the best script developers to get their work highlighted.”

In short, the library consists in a set of ASP.NET controls to develop web application with ajax in a very simple way. For example, inside the library you will find:

  • Animation
  • Auto complete
  • Calendar
  • Drag panel
  • Modal popup
  • Textbox watermark

To use all of this controls, you just need to download the library and include in your Visual Studio Toolbar. So, you will be able to see the controls and drag and drop them inside your application.

All the extender controls (controls that add functionalities to an another existing control) have a commun atribute called TargetControlID, which identify the extended control. So, in the most of situations, all you have to do is to set this attribute value as shown in the Calendar example below:

<ajaxToolkit:Calendar runat="server"
    TargetControlID="Date1"
    CssClass="ClassName"
    Format="MMMM d, yyyy"
    PopupButtonID="Image1" />

More information and examples here. See you


Fernando

September 9, 2008

Interface Unit Tests with Selenium

Filed under: testing, web — Tags: — nandokakimoto @ 3:50 am

Hi,

this week started with tests development, since I took the responsability of testing a Web Application. However, different from the others tests that I’ve done in the past, which covered C# code,  this ones are related to the project’s user interface. So, testing javascript code and interface functionality are now part of my work. Due to that, I found and amazing IDE with this puporse: let me show you Selenium.

“Selenium IDE is a Firefox addon that records clicks, typing, and other actions to make a test, which you can play back in the browser. Selenium IDE is not only recording tool: it is a complete IDE. You can choose to use its recording capability, or you may edit your scripts by hand”.

Here, is some of its features:

  • Easy record and playback
  • Intelligent field selection will use IDs, names, or XPath as needed
  • Autocomplete for all common Selenium commands
  • Walk through tests
  • Debug and set breakpoints
  • Save tests as HTML, Ruby scripts, Java, C# or any other format
  • Option to automatically assert the title of every page

All you have to do is to recorde yourself a test by doing some actions with your mouse and keyboard in a web page, and later reproduce the test as if you were doing the working again. With that, is possible to test almost everything you want to check in a html code, which means, in the interface of the web page.

Let’s do an easy example. First of all, install the firefox extension here. After restarting your firefox, let’s navigate to the google home page and open the Selenium IDE by clicking on Tools -> Selenium IDE. Remember to press the recorde button, as show in the picture below, to start recording the test.

Now, type “Talking about computer science” and press OK. Later, click on the first occurency of the search, redirecting you to my blog :)

Now, select “nandokakimoto” and with the rigth button choose “verifyTextPresent nandokakimoto”, which means that the test will look for this text when it runs.

It’s done! Now stop the test by clicking again on the record button in Selenium IDE. Take a  look at the set of commands shown in the table to verify if the are correct. Then, it’s time to run the test and see the result. So, click on the run icon, as show in the picture below, and you will see that the test run with success.

To see the test code in C#, Ruby or Java code, just click on Options -> Format and choose your prefered language. It’s really easy. Now, go forward and create your own interface tests.

See you,


Fernando

September 5, 2008

ASP.NET and Google Maps – part 2

Filed under: ASP.NET, google, web — Tags: — nandokakimoto @ 3:05 pm

Hi,

in the last post, we talked about how to integrate an ASP.NET application with google maps. But, we didn’t do anything interesting at all. Today, I will show some features of the google maps API so your application can be more funny. What about an application that show how to people arrive in your home from anywhere? So, let’s do it now.

First off all, you will need to find the latitude and longitute of your home. For that, use the permalink of http://maps.google.com. There you can search for coordinates and use them in your javascript code. For example, after a search for my address I got the follow URL when click on Link option:

http://maps.google.com/maps?f=q&hl=pt-BR&geocode=&q=R.+General+Luis+Mallet,+Recife&sll=-8.126297,-34.905066&sspn=0.009644,0.013819&ie=UTF8&ll=-8.126212,-34.904251&spn=0.009644,0.013819&t=h&z=16&iwloc=addr

So, as you can see, my home is located on (-8.126212,-34.904251), so I used this valued to set the center of my map with the funtion setCenter(point, zoom?). To add a reference to your home, let’s use a map marker. You will need to create a marker in a specific point with the marker constructor GMarker(point) and add the marker in the map with the function addOverlay(marker). After this operations your javascript will be like that:

Now, if you compile and run you application, you will see the marker over your home on map.

All right, now let’s create the ASP.NET controllers that your friends will use to type their address. I will use that a Labe, a TextBox and a Button. So, after that my form will be like this:

Because we are calling a javascript function,  I’ve allready set the button click event using OnClientClick. In this function we will have to:

  1. Get the textfield value;
  2. Create a new google directions object;
  3. Use the function directions.load() to return a route from your friend’s address to yours.

The searchRoute function is shown below:

Here, we use the ClientID property to get the server control identifier generated by ASP.NET. All we have to do later is to create a string in the format from: Source to: Destination and call the function directions.load(). Notice that I’m using my coordinates as destination, so in your case, just use yours.

Because every ASP.NET control sends a PostBack to the server, we will have to use some Ajax to view the result. If we don’t use Ajax, the page will be reloaded (and also the map since the function load() well be called to our form). To prevent that, we just have to use a ScriptManner and an UpdatePanel, which will make that just a part of the page is reloaded after the button click event.

Our new <body> is show belown:

If it’s still not working, remember to type the whole address, with city, country, etc.

Today we talked about more google maps API features and created a simple application that shows how to arrive to you home from anywhere.  To learn more about google maps and its API take a look at google maps API documentation.

See you.


Fernando

September 3, 2008

ASP.NET and Google Maps

Filed under: ASP.NET, google — Tags: — nandokakimoto @ 6:14 am

Hi,

last moth I was little busy with graduation thesis’ activities, so I could not give such attention to the blog. But, I’ll try to write as soon as I have some time. Today, I’ll talk about how to create an ASP.NET application that integrates with google maps. This has been my work on Inove for the last two moths and it’s quite interesting. Let’s start.

First, let’s create our Web application in Visual Studio by clicking on File -> New Project… and choosing a new ASP.NET Web Application, as shown in figure below:

Later, run the project with F5 and copy your start page URL. With your web site URL, sign up for a google maps API key here. You just need to agree with the term and conditions, and paste your web site URL inside the tex box. Now, copy the javascript content of the given html and paste it into the head tag of your .aspx file. . Now, your head tag will be similar to the code show below.

In line 15, we create a new instance of google maps, passing the <div> tag which contains the maps. In line 16 we set where the map will be center on and the map zoom. Fell free to change this values.

Now, to visualize the map, will need two things:

  1. The map is supposed to be in a separate <div> tag. If you take a look at the javascript code, you will see something like document.getElementById(“map”). So, what you have to do is to create a new <div> tag, inside de body, which id property is “map”.
  2. You will need to call the function load(), so the map can be loaded. To do that, just use onload event in the <body> tag, passing the function load() as value.

After that, your <body> will look like this:

Notice that a use a style to set the size of the map.

Now, all that you have to do is to compile and run your project by pressing F5.
Very easy, don’t you think?

So, in this post I talked about how to integrate an ASP.NET application with google maps. In the next posts, I’ll talk more about this integration by addin markers, controllers and some functions.

See you in the next post


Fernando

Blog at WordPress.com.