Posts

What is Design By Contract

Design by Contract is a trademarked term of BertrandMeyer and implemented in his EiffelLanguage as assertions. Design By Contract (DbC) is a software correctness methodology. It uses preconditions and postconditions (Contracts) to programmatically assert the change in state caused by a piece of a program. The Preconditions and Postconditions that are in demand in DbC could summarized by the "three questions" that the designer must repeatedly ask:     * What does it expect?     * What does it guarantee?     * What does it maintain? Some attributes of Design By Contract... Classes should specify their invariants: what is true before and after executing any public method. Methods should specify their pre- and post-conditions: what must be true before and what must be true after their execution, respectively. Pre-conditions may be weakened by subclasses and post-conditions may be strengthened. The explicit definition of these "assertions" forces the designer to th...

Static Import In Java 5

Constant Interface Anti pattern is a real hot topic of discussion in java, after browsing the web for hours I am not sure whether to use it or avoid it. Constant Interface is a interface which defines some public static final constants. And when we need those constants we can implement the Interface and uses the defined constants or we can access the static constants as InterFaceName.ConstantName. The book Effective Java by Joshua Bloch discusses this problem he calls it "Constant Interface Anti pattern." Poor use of interfaces and  Exposes Implementation Detail are some of the issues why author advocates to avoid it. public interface Constants {       public static final double PI = 3.14159;       public static final double PLANCK_CONSTANT = 6.62606896e-34;   }     public class Calculations implements Constants {       public double getReducedPlanckConstant() {         return PLANCK_CONSTANT / (2 * PI);     }   } Java 5 comes with a Static Import concept. We can solve the...

Liquibase Incremental Database Changes

LiquiBase is used for managing, tracking and applying database changes. It uses XML file for storing incremental changes to data base.These xml file stores both Database structures(DDL) and codes.LiquiBase is an open source (LGPL) Library The following are some of the features which attract LiquiBase a lot 1) It is Open Source 2) It is Database independent 3) Supports rolling back changes 4) Supports merging of changes from multiple developers The XML file which contains input to Liquibase is called databaseChangeLog File. The following is a example of a empty databaseChangeLog file <databaseChangeLog         xmlns=" http://www.liquibase.org/xml/ns/dbchangelog/1.8 "         xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance "         xsi:schemaLocation=" http://www.liquibase.org/xml/ns/dbchangelog/1.8         http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.8.xsd "> </databaseChangeLog> The following fragment is a changeset, the...

Google Using Yahoo Libraries?

It seems that google is also using Yahoo Libraries. YUI is a product from yahoo, YUI stands for Yahoo User Interface. To know more about YUI visit http://developer.yahoo.com/yui/ . Google seems to be using yui for layout, as it seems like by the following URL, http://ajax.googleapis.com/ajax/libs/yui/2.6.0/build/yuiloader-dom-event/yuiloader-dom-event.js Clearly It seems like YUI is hosted on google server too. YUI is a great tool, it provides tools for creating rich web application and ajax tools.

Java Annotation

Annotations on Annotations(Meta Annotation) J2SE 5.0 provides four annotations in the java.lang.annotation package that are used only when writing annotations:     @Documented—Whether to put the annotation in Javadocs     @Retention—When the annotation is needed     @Target—Places the annotation can go     @Inherited—Whether subclasses get the annotation These four annotations are used while creating custom Annotations and are called Meta Annotations. The Target annotation The target annotation indicates the targeted elements of a class in which the annotation type will be applicable. It contains the following enumerated types as its value:      @Target(ElementType.TYPE)—can be applied to any element of a class      @Target(ElementType.FIELD)—can be applied to a field or property      @Target(ElementType.METHOD)—can be applied to a method level annotat...

Java Annotation

Annotation in Java is there to make programmers life a bit easy. Annotation-based development relieves Java developers from the pain of cumbersome configuration. Advantages of using Annotations Annotations are attached to Classes and can be processed via reflection. It is much easier to see the Annotations as they are defined in Java code and no need to refer external configurations (like XML). Compiler will do static type checking for Annotation uses. Compile time the proper uses of annotation will be done. Here are some rules-of-thumb when defining an annotation type: Annotation declaration should start with an 'at' sign like @, following with an interface keyword, following with the annotation name. Method declarations should not have any parameters. Method declarations should not have any throws clauses. Return types of the method should be one of the following: primitives String Class enum array of the above types The following shows example of decel...

3 Column Page Design using YUI

The Yahoo! User Interface Library (YUI) is a collection of Java script and CSS, which helps  for building rich interactive web applications quickly.  The CSS components provide a collection of CSS which when used correctly helps us to produce nice and complex layouts. The following ★reset.css normalizes margins, padding, etc. ★fonts.css sets font baseline & even scaling ★grids.css defines classes for preset height and widths of div html elements ★base.css Base is an optional CSS file that complements YUI's core CSS foundation (Reset, Fonts, and Grids). While Reset removes and neutralizes the inconsistent default styling of HTML elements, Base applies a consistent style foundation for common HTML elements across A-grade browsers In the following example I have created a Three column page structure using YUI CSS Framework. <html> <head> <title>Reworked with YUI Grids CSS</title>   <link rel="stylesheet" type="text...