Mar 202009
 

Inheritance is one of Object-Oriented concept. Since Ruby is an Object-Oriented Programming, it has implemented the Inheritance functionality.


#intialize global variable
$value = 0

class Parent
    def parent_value
        $value = 5
    end
end

class Child < Parent
    def child_value
        $value = 10
    end
end

child = Child.new

#calling parent_method using child object
base_value = child.parent_value

#calling child_method
derive_value = child.child_value

#display result
puts "Here's parent value: #{base_value}"
puts "Here's child value: #{derive_value}"

Sample Result:

Here’s parent value: 5
Here’s child value: 10
Mar 202009
 

class Encapsulation
    def get_value
        @value
    end

    def set_value value
        @value = value
        return nil
    end
end

encapsulation = Encapsulation.new
encapsulation.set_value(15)
puts encapsulation.get_value

In this code, you cannot mess around with the state of its variable @value. The only way you can access it is through get & set method (get_value, set_value). This is the encapsulation

Sample Result

15
Mar 192009
 

Here just how’s  to declare global, class, instant, and local variables in Ruby:


$global_variable = "global variable"

class First
    @@class_variable = 0

    def display_global_variable
        puts "#{$global_variable} access from class 'First'"
    end

    def class_variable
        @@class_variable += 1
        puts "value of class variable : #{@@class_variable}"
    end
end   

class Second
    def initialize(id,name)
        @id = id # id is a local variable
        @name = name # name is a local variable
    end

    def display_global_variable
        puts "#{$global_variable} access from class 'Second'"
    end

    def display_instance_variable
        puts "display value of instance variable id = #{@id}, name = #{@name} "
    end
end

#instantiate object
first = First.new
second = Second.new(1, "borey")

#Demonstrate on class variable
first.display_global_variable
second.display_global_variable
puts "\n"

#Demonstrate on class variable
first.class_variable
first.class_variable
puts "\n"

#Demonstrate on instance variable
second.display_instance_variable

Here’s the result after code is executed:

global variable access from class ‘First’
global variable access from class ‘Second’

value of class variable : 1
value of class variable : 2

display value of instance variable id = 1, name = borey

Mar 042009
 

In object-oriented programming, the open/closed principle states “software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification”; that is, such an entity can allow its behavior to be modified without altering its source code.

Modules that conform to the open-closed principle have two primary attributes:

  1. They are “Open For Extension”. This means that the behavior of the module can be extended. That we can make the module behave in new and different ways as the requirements of the application change, or to meet the needs of new applications.
  2. They are “Closed for Modification”. The source code of such a module is inviolate. No one is allowed to make source code changes to it.

In the implementation of this principle, normally, the abstract interfaces are used.

Feb 272009
 

Today, just trying to find gedit’s alternative editor. gedit is an editor running on Linux which is good for coding Javascript as it has many useful plug in. Since my workstation at home doesn’t run on Linux, I have find another alternative to gedit. After googling about a half hour, I found out about jEdit. After installing jEdit & install some extra plug in, i can see that jEdit is good as compare to gedit.

Feb 092009
 

Since i’m going to write some code for the client side, I have to start learning OO javascript. What makes me surprise the most is how it is written. here are some codes i have tested:


as you can see in the code, i only create one function, however i can call in different ways. This is how dynamic Javascript is. Really Really dynamic!!!!

Delicious

 Uncategorized  No Responses »
Feb 062009
 

Well, i suppose some people have heard or already own an account on this site.

What is Delicious?

Delicious is a social bookmarking service that allows users to tag, save, manage and share web pages from a centralized source. With emphasis on the power of the community, Delicious greatly improves how people discover, remember and share on the Internet.

Things you can do with Delicious

Bookmark any site on the Internet, and get to it from anywhere

Instead of having different bookmarks on every computer, Delicious makes it easy to have a single set of bookmarks kept in sync between all of your computers. Even if you’re not on a computer you own, you can still get to your bookmarks on the Delicious website.

Share your bookmarks, and get bookmarks in return

If your friends use Delicious, you can send them interesting bookmarks that they can check out the next time they log in. Of course, they can do the same for you. As you explore the site and find interesting users, you can use our Subscriptions and Network features to keep track of the Delicious tags and users you find most interesting.

Discover the most useful and interesting bookmarks on the web

See what’s hot with Delicious users by checking out our popular tags. By looking at popular bookmarks for a tag, you’ll be able to discover the most interesting bookmarks on the topics you’re most interested in. Browse bookmarks on just about anything from the best programming tips to the most popular travel sites, all in an easy to read format.

source: http://delicious.com

more about c#

 Uncategorized  No Responses »
Jan 162009
 

Well, i have spent these few days studying on C# on more difficult topic. I have touch on abstract class, interface, indexer, exception handler, and generic. So far, i feel C# is very impressive.

Comparing to other programming language i have studied before like java or C++, i found that code in C# is easier to implement than in java or C++. I’m not so sure about the database yet, since i haven’t really touch on LINQ in C#.

Jan 092009
 

As required by work, i have started new programming language and tool. During this whole week, i have read book and doing some practice. I have found out that C# is similar to java. With the background from java, i can easy get the concept.

Also i have read on NHibernate. It’s a framework that help to connect to SQL Database, which i need to use to develop my project.

Jan 042009
 

Welcome all friends & visitors!!!

Well, first of all, just wanna talk about what will this blog all about. I will update all contents which are related to technology (mostly will be related to IT field) and things which are useful to our daily life. I’ll try to make this blog updated most of the time.

Thanks

© 2012 Programming & technology Suffusion theme by Sayontan Sinha