Car myFerrai = new Car();
Car myFriendsFerrari = new Car();
Tyre tyre = myFerrari.removeTyre();
Tyre flatTyre = myFriendsFerrari.replaceTyre(tyre);
myFriendsFerrari.drive();
new StringBuffer("start").append("more").append("more")Obviously the return statement of the append method should look likereturn this;
Later I came across more interesting examples of this in the mock libraries like below.
Expect.Call(someObj.someMethod()).Return(anotherObject).Repeat().Once();Look at this now."Create a new bug on build 45576 with description "this is really bugging ....". new Bug("new one").onBuild(45576).withDescription("this is really bugging")
   .WithPriority("medium").reportedBy("QA")and this bug = new Bug("new one"); bug.setDescription("...."); bug.setBuild(45576)...... We can improve the readability by adding 'And', 'With', 'To' etc.Below I have added a creational method and used 'and' method toimprove the readability a bit more.
  Bug.CreateWithTitle("new one").onBuild(45576)  .withDescription("this is really bugging").WithPriority("medium").reportedBy("QA").and().assignTo("a dev")...
// This was the closest i could get in java.// still confused about the terminology 'SingletonMethod'
public class SingletonMethodJava {
    void theOnlyMethod(){
        System.out.println("theOnlyMethod");
    }
    public static void main(String[] args){
         new SingletonMethodJava(){
              void addedOneMoreMethod(){
                System.out.println("addedOneMoreMethod");
              }
         }.addedOneMoreMethod();
    }
}
class SingletonMethodRuby
    def theOnlyMethod
        puts "theOnlyMethod";
    end
end
singleton_method = SingletonMethodRuby.new
def singleton_method.addedOneMoreMethod
 puts "addedOneMoreMethod";
end
singleton_method.addedOneMoreMethod
  
   
    
require '../../poi-3.0.1-FINAL-20070705.jar'
include Java
include_class java.io.FileInputStream
include_class Java::org.apache.poi.hssf.usermodel.HSSFWorkbook
include_class Java::org.apache.poi.hssf.usermodel.HSSFSheet
include_class Java::org.apache.poi.hssf.usermodel.HSSFRow
include_class Java::org.apache.poi.hssf.usermodel.HSSFCell
class ExcelWorkBook
def initialize(xlsFile)
input = FileInputStream.new(xlsFile)
@hssfworkbook = HSSFWorkbook.new(input)
end
def worksheet(sheet_position)
ExcelWorkSheet.new(@hssfworkbook.getSheetAt(sheet_position),sheet_position)
end
class ExcelWorkSheet
def initialize(hssfworksheet, sheet_position)
@index = sheet_position
@hssfworksheet = hssfworksheet
end
def row_at(rownumber)
return Row.new(@hssfworksheet.getRow(rownumber))
end
def rows
rows = []
for row in @hssfworksheet.rowIterator
rows << Row.new(row)
end
rows
end
class Row
def initialize(hssfrow)
@hssfrow = hssfrow
end
def value_at(columnindex)
cell = @hssfrow.getCell(columnindex)
if(cell == nil)
''
elsif(HSSFCell::CELL_TYPE_NUMERIC == cell.getCellType())
cell.getNumericCellValue()
elsif(HSSFCell::CELL_TYPE_STRING == cell.getCellType())
cell.getRichStringCellValue()
end
end
end
end
end

I am passionate about making Better Software Solutions,that helps businesses to stay agile, by applying Agile,Lean and Systems Thinking principles. Also I grow coffee,spices and in general has big interest in pesticide free food!
Subscribe to
Comments [Atom]