CSC/ECE 517 Fall 2007: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
 
(28 intermediate revisions by 2 users not shown)
Line 1: Line 1:
CSC- 517 Object-Oriented Languages and Systems
=== Summary of pages done in Fall 2007 and Summer 2008 ===
                                      Wiki Assignment


Topic 2 :  There are plenty of examples of method_missing on the Web. Unfortunately, I find most of them rather difficult to understand. One needs to look at quite a bit of source code and figure out what it does. Fix this by giving a plain-English description of several uses of method_missing not covered in our class, with Web links to the pages where you found them.
* Lecture 4
Ruby has a powerful way to intercept calls to undefined method. This is implemented by defining method_missing in our class definition. If a call is made to an undefined method on a object, Ruby passes the name of the method and its arguments to the method_missing. This is an efficient and safest way to intercept calls made to unknown methods and handles them in a proper fashion.
** [[CSC/ECE 517 Fall 2007/wiki1 2 316|Callbacks using Ruby closure vs. Smalltalk callbacks]]
Let us look into few examples (Link used http://rubylearning.com/satishtalim/ruby_method_missing.html
** [[CSC/ECE 517 Fall 2007/wiki1 2 pk|Callbacks using Ruby closure vs. Smalltalk callbacks]]
  class Dummy 
** [[CSC/ECE 517 Fall 2007/wiki1 3 b6|Currying in Ruby]]
def method_missing(m, *args)  
** [[CSC/ECE 517 Fall 2007/wiki1 3 c1|What is currying?]]
puts "There's no method called #{m} here please try again." 
** [[CSC/ECE 517 Fall 2007/wiki1b 3 an|Closures]]
end 
* Lecture 5
end 
** [[CSC/ECE 517 Fall 2007/wiki1 1 aman|Hash maps in Java vs hashes in Ruby]]
Dummy.new.anything 
** [[CSC/ECE 517 Fall 2007/wiki1 1 ss|Compare hashes in Ruby with HashMaps in Java]]
>ruby tmp.rb 
** [[CSC/ECE 517 Summer 2008/wiki1 6 arraysandhashes|Arrays and hashtables]]
Output: There's no method called anything here -please try again.  
** [[CSC/ECE 517 Summer 2008/wiki1 6 c9)|Arrays and hashtables]]
In the above example, a call is made to a method called anything on object of class Dummy. There is no method called “anything” defined within the class. Ruby passes the name “anything” to method_missing. Hence the above output is displayed.  
** [[CSC/ECE 517 Summer 2008/wiki1 6 jm|Arrays and hashtables]]
 
** [[CSC/ECE 517 Fall 2007/wiki1b 2 22|Method missing]]
Another use of method_missing: (Link http://redhanded.hobix.com/inspect/theBestOfMethod_missing.html)
** [[CSC/ECE 517 Fall 2007/wiki1b 2 Method Missing|Method missing]]
 
** [[CSC/ECE 517 Fall 2007wiki2 c9|Method missing]]
def method_missing(method)
** [[CSC/ECE 517 Fall 2007/wiki1b 2 c9|Example of Method missing]]
    @posts = User.find_first(['username = ?', method.to_s]).posts
** [[CSC/ECE 517 Fall 2007/wiki1b 2 p2|Example of Method missing]]
    render_action 'index'   
** [[CSC/ECE 517 Fall 2007/wiki1 2 p2|Explain method_missing]]
    cache_page if ActionController::Base.perform_caching
* Lecture 6
end
** [[CSC/ECE 517 Fall 2007/wiki1 4 01|Private methods in Ruby compared with Java]]
 
** [[CSC/ECE 517 Fall 2007/wiki1 4 ar|Private method invocation in Ruby]]
The above code is an example of a controller used for generating RSS and Atom Feeds to user. It is used by Elite Journal which is a multi user. Since their webpage changes display every now and then depending upon the status of user login. Therefore caching the output is very hard. Therefore, most of the time the output is not cached. So, generally the RSS and Atom Feeds are cached.  Since Elite Journal is multi-user, there is a feed for each user. This feed is combined with the method_missing call such that a call to the /rss/scott URL will retrieve the feed to the user “Scott”. In the above example, the page is cached if caching is enabled by the action controller.
** [[CSC/ECE 517 Fall 2007/wiki1 5 ap|Duck typing vs. interfaces]]
Another set of example for the use of method_missing is as follows: (Link: facets.rubyforge.org/src/lib/facets/core/kernel/as.rb)
** [[CSC/ECE 517 Fall 2007/wiki1 5 sl|Duck typing vs. interfaces and inheritance]]
def method_missing(sym, *args, &blk)
** [[CSC/ECE 517 Summer 2008/wiki1 1 mb|Regular expressions in Ruby vs. Java]]
  @ancestor.instance_method(sym).bind(@subject).call(*args,&blk)
** [[CSC/ECE 517 Summer 2008/wiki1 1 mf|Regular expressions in Ruby vs. Java]]
end
** [[CSC/ECE 517 Summer 2008/wiki1 1 rapodraz|Regular expressions in Ruby vs. Java]]
require 'rubygems'
** [[CSC/ECE 517 Summer 2008/wiki1 1 rp|Regular expressions in Ruby vs. Java]]
require 'facets'
* Lecture 7
 
** [[CSC/ECE 517 Fall 2007/wiki1 6 b2|Mixins]]
module James
** [[CSC/ECE 517 Fall 2007/wiki1 6 c9|Inheritance and mixins]]
  def name
** [[CSC/ECE 517 Fall 2007/wiki1 7 a23|Multiple inheritance and mixins]]
    "James"
** [[CSC/ECE 517 Fall 2007/wiki1 7 c9|Mixins vs. multiple inheritance]]
  end
** [[CSC/ECE 517 Fall 2007/wiki1 8 s1|extend method]]
end
* Lecture 8
 
** [[CSC/ECE 517 Fall 2007/wiki1b 4 19|Metaprogramming in Ruby]]
module Lynn
** [[CSC/ECE 517 Fall 2007/wiki1b 4 am|Metaprogramming in Ruby]]
  def name
** [[CSC/ECE 517 Fall 2007/wiki1b 4 pm|Metaprogramming in Ruby]]
    "Lynn"
** [[CSC/ECE 517 Fall 2007/wiki1b 5 b4|Aspect-oriented programming and AspectR]]
  end
** [[CSC/ECE 517 Summer 2008/wiki1 3 aobk|Reflection]]
end
** [[CSC/ECE 517 Summer 2008/wiki1 3 jb|Reflection]]
 
** [[CSC/ECE 517 Summer 2008/wiki1 3 ref|Reflection]]
class FamilyMember
** [[CSC/ECE 517 Summer 2008/wiki1 7 ev|eval()]]
  include James
** [[CSC/ECE 517 Summer 2008/wiki1 7 n1|eval()]]
  include Lynn
* Lecture 9
end
** [[CSC/ECE 517 Fall 2007/wiki1b 6 aa|Singleton in Ruby and Java]]
 
** [[CSC/ECE 517 Fall 2007/wiki1b 6 c1|Singleton in Ruby and Java]]
FamilyMember.ancestors # => [FamilyMember, Lynn, James, Object, Kernel]
* Lecture 10
member = FamilyMember.new
** [[CSC/ECE 517 Fall 2007/wiki1b 7 as|Command patterns]]
member.name # => "Lynn"
** [[CSC/ECE 517 Fall 2007/wiki1b 7 c9|Command pattern]]
member.as(James).name # => "James"
** [[CSC/ECE 517 Fall 2007/wiki1b 7 vs|Command pattern]]
 
** [[CSC/ECE 517 Fall 2007/wiki1b 8 ktrk|Strategy in Ruby and Java]]
In above example method_missing definition allows you to call a method on any ancestor. Initially instance of FamilyMember i.e member receives a message as which returns an instance of As. After returning the instance of As, member receives messae “name”. Since As does not contain the definition of name, the method_missing is called where in name is passed as an arguments. Within the method, instance_method is called on the ancestor with the name as the symbol. The instance_method will return the unbound method name since it is not defined. Then, method_missing binds the name to the subject which is member (instance of FamilyMember) and sends a call message along with the arguments passed before. Here, since name binds to the member, it can access the state or behavior of the member.
** [[CSC/ECE 517 Fall 2007/wiki1b 8 sa|Strategy in Ruby and Java]]
Last example for the purpose of using method_missing. (Link http://services.tucows.com/developers/2007/08/03/rubys-method_missing-method-explained-with-lolcats/)
* Lecture 12
class LolCat
** [[CSC/ECE 517 Fall 2007/wiki2/3 rl|Model/View/Controller in Ruby and Java]]
 
** [[CSC/ECE 517 Fall 2007/wiki2 3 bp|Resources on MVC]]
  def confess
** [[CSC/ECE 517 Fall 2007/wiki2 1 p23|Ruby on Rails vs. Apache Struts]]
    puts “I made you a cookie…but then I eated it.”
** [[CSC/ECE 517 Fall 2007/wiki2 1 pp|Ruby on Rails vs. Apache Struts]]
  end
** [[CSC/ECE 517 Fall 2007/wiki2 1 rl|Ruby on Rails vs. Apache Struts]]
 
* Lecture 13
  def eat
** [[CSC/ECE 517 Fall 2007/wiki2 2 22|Object-relational mapping]]
    puts “NOM NOM NOM.”
** [[CSC/ECE 517 Fall 2007/wiki2 2 aa|Object-relational mapping]]
  end
** [[CSC/ECE 517 Fall 2007/wiki2 2 d4|Object-relational mapping]]
 
** [[CSC/ECE 517 Summer 2008/wiki3 1 ar|RDB/OO patterns]]
  def method_missing(method)
** [[CSC/ECE 517 Summer 2008/wiki3 1 th|RDB/OO patterns]]
    puts “Oh noes! I has no idea how to #{method}.”
** [[CSC/ECE 517 Summer 2008/wiki3 7 SHOP PAT|Shopper pattern]]
  end
** [[CSC/ECE 517 Summer 2008/wiki3 7 shopper|Shopper pattern]]
 
** [[CSC/ECE 517 Summer 2008/wiki3 7 ws|Shopper pattern]]
end
* Lecture 14
 
** [[CSC/ECE 517 Fall 2007/wiki2 5 as|CRC cards]]
> kitty = LolCat.new
** [[CSC/ECE 517 Fall 2007/wiki2 5 kq|CRC cards]]
=> #<LolCat:0x349a40>
** [[CSC/ECE 517 Fall 2007/wiki2 5 pr|CRC cards]]
 
* Lecture 15
> kitty.confess
** [[CSC/ECE 517 Fall 2007/wiki2 4 2q|Use cases]]
I made you a cookie...but then I eated it.
** [[CSC/ECE 517 Fall 2007/wiki2 4 dj|Use cases]]
=> nil
** [[CSC/ECE 517 Fall 2007/wiki2 4 np|Use cases]]
 
** [[CSC/ECE 517 Summer 2008/wiki2 3 uml|Resources for use cases]]
> kitty.eat
** [[CSC/ECE 517 Summer 2008/wiki2 4 acmoore2|Resources for use cases]]
NOM NOM NOM.
* Lecture 16
=> nil
** [[CSC/ECE 517 Fall 2007/wiki1b 1 as|Using namespaces and aliases to avoid method-name conflicts]]
 
** [[CSC/ECE 517 Fall 2007/wiki2 6 ap|Type vs. class]]
> kitty.poop
** [[CSC/ECE 517 Fall 2007/wiki2 6 mxz|Type vs. class]]
Oh noes! I has no idea how to poop.
** [[CSC/ECE 517 Fall 2007/wiki2 6 ubs|Type vs. class]]
=> nil
** [[CSC/ECE 517 Fall 2007/wiki2 8 42|Overloading vs. overriding]]
 
** [[CSC/ECE 517 Fall 2007/wiki2 8 c9|Overloading vs. overriding]]
In the above example, we create an instance of LolCat which is named kitty. Next, call the method “confess” on kitty. Since it is defined , the method “confess” is called and appropriate result is printed. When the method poop is called, the method_missing is called since the method “poop” is not defined. Ruby passes the name of the method i.e “confess” and arguments that are needed to the method “poop”. The method_missing displays an error accordindly.
** [[CSC/ECE 517 Summer 2008/wiki2 2 ao|Variable-naming conventions]]
** [[CSC/ECE 517 Summer 2008/wiki2 2 ar|Variable-naming conventions]]
** [[CSC/ECE 517 Summer 2008/wiki2 2 rapodraz|Variable-naming conventions]]
** [[CSC/ECE 517 Summer 2008/wiki2 3 kb|Resources for learning about UML]]
* Lecture 17
** [[CSC/ECE 517 Summer 2008/wiki1 8 dm|Prototype-based programming examples]]
** [[CSC/ECE 517 Summer 2008/wiki1 8 smr|Prototype-based programming examples]]
** [[CSC/ECE 517 Summer 2008/wiki1 Assignment|Prototype-based programming examples]]
* Lecture 18
** [[CSC/ECE 517 Fall 2007/wiki2 10 ab|Inheritance vs. delegation]]
** [[CSC/ECE 517 Fall 2007/wiki2 10 c4|Inheritance vs. delegation]]
** [[CSC/ECE 517 Fall 2007/wiki2 10 cv|Inheritance vs. delegation]]
** [[CSC/ECE 517 Summer 2008/wiki2 8 Inh-Del|Inheritance vs. delegation]]
** [[CSC/ECE 517 Summer 2008/wiki2 8 jb|Inheritance vs. delegation]]
* Lecture 19
** [[CSC/ECE 517 Fall 2007/wiki3 1 sa|Support for assertions]]
** [[CSC/ECE 517 Fall 2007/wiki3 1 vb|Support for assertions]]
** [[CSC/ECE 517 Fall 2007/wiki3 2 at|Examples of programming by contract]]
** [[CSC/ECE 517 Fall 2007/wiki3 2 bp|Examples of programming by contract]]
** [[CSC/ECE 517 Fall 2007/wiki3 2 c4|Examples of programming by contract]]
** [[CSC/ECE 517 Fall 2007/wiki3 2 dp|Examples of programming by contract]]
* Lecture 20
** [[CSC/ECE 517 Fall 2007/wiki2 7 an|Cohesion and coupling]]
** [[CSC/ECE 517 Fall 2007/wiki2 7 as|Cohesion and coupling]]
** [[CSC/ECE 517 Fall 2007/wiki2 7 b2|Cohesion and coupling]]
** [[CSC/ECE 517 Summer 2008/wiki2 5 mo|Cohesion and coupling]]
** [[CSC/ECE 517 Summer 2008/wiki2 6 cc|Cohesion and coupling]]
** [[CSC/ECE 517 Summer 2008/wiki2 c6 CohCoupling|Cohesion and coupling]]
** [[CSC/ECE 517 Summer 2008/wiki3 3 cd|Low coupling]]
** [[CSC/ECE 517 Summer 2008/wiki3 3 dm|Low coupling]]
** [[CSC/ECE 517 Summer 2008/wiki3 3 lc|Low coupling]]
** [[CSC/ECE 517 Summer 2008/wiki3 3 n1|Low coupling]]
** [[CSC/ECE 517 Summer 2008/wiki3 4 bk|Cohesion]]
** [[CSC/ECE 517 Summer 2008/wiki3 4 mb|Cohesion]]
* Lecture 21
** [[CSC/ECE 517 Fall 2007/wiki3 10 10|The agile debate]]
** [[CSC/ECE 517 Fall 2007/wiki3 10 ljh|The agile debate]]
** [[CSC/ECE 517 Fall 2007/wiki3 10 sb|The agile debate]]
** [[CSC/ECE 517 Fall 2007/wiki3 10 tm|The agile debate]]
** [[CSC/ECE 517 Fall 2007/wiki3 9 mdkt|Collective ownership, continuous integration]]
** [[CSC/ECE 517 Fall 2007/wiki3 9 p1|Collective ownership, continuous integration]]
** [[CSC/ECE 517 Fall 2007/wiki3 9 pp|Collective ownership, continuous integration]]
** [[CSC/ECE 517 Fall 2007/wiki3 9 sm|Collective ownership, continuous integration]]
* Lecture 22
** [[CSC/ECE 517 Summer 2008/wiki1 2 acmoore2|Iterators and generators]]
** [[CSC/ECE 517 Summer 2008/wiki1 2 i2|Iterators and generators]]
** [[CSC/ECE 517 Summer 2008/wiki1 2 itr|Iterators and generators]]
** [[CSC/ ECE 517 Fall 2007/wiki3 5 pr|Creator and Factory patterns]]
* Lecture 23
** [[CSC/ECE 517 Fall 2007/wiki2 c9|Observer pattern]]
* Lecture 25
** [[CSC/ECE 517 Summer 2008/wiki1 5 a5|Hooks in Ruby and Java]]
** [[CSC/ECE 517 Summer 2008/wiki1 5 bk|Hooks in Ruby and Java]]
* Lecture 26
** [[CSC/ECE 517 Summer 2008/wiki2 4 uc|DRY principle]]
** [[CSC/ECE 517 Summer 2008/wiki2 5 31|DRY principle]]
* No current lecture
** [[CSC/ECE 517 Fall 2007/wiki1 1 as|Disambiguating method calls]]
** [[CSC/ECE 517 Fall 2007/wiki1b 1 c4|Disambiguating multiple instances of a method]]
** [[CSC/ECE 517 Fall 2007/wiki3 3 aa|Interface segregation principle]]
** [[CSC/ECE 517 Fall 2007/wiki2 9 A3|Principle of least astonishment]]
** [[CSC/ECE 517 Fall 2007/wiki2 9 NT|Principle of least astonishment]]
** [[CSC/ECE 517 Fall 2007/wiki2 9 kk|Principle of least astonishment]]
** [[CSC/ECE 517 Fall 2007/wiki3 3 33|Separation of responsibility]]
** [[CSC/ECE 517 Fall 2007/wiki3 3 ab|Separation of responsibility]]
** [[CSC/ECE 517 Fall 2007/wiki3 3 as|Separation of responsibility]]
** [[CSC/ECE 517 Fall 2007/wiki3 3 qq|Separation of responsibility]]
** [[CSC/ECE 517 Fall 2007/wiki3 4 aa|Interface segregation principle]]
** [[CSC/ECE 517 Fall 2007/wiki3 4 rl|Interface segregation principle]]
** [[CSC/ECE 517 Fall 2007/wiki3 4 s2|Interface segregation principle]]
** [[CSC/ECE 517 Fall 2007/wiki3 4 sa|Interface segregation principle]]
** [[CSC/ECE 517 Fall 2007/wiki3 5 ab|Creator pattern]]
** [[CSC/ECE 517 Fall 2007/wiki3 5 ld|Creator pattern]]
** [[CSC/ECE 517 Fall 2007/wiki3 5 ns|Creator pattern]]
** [[CSC/ECE 517 Fall 2007/wiki3 6 aa|Controller pattern]]
** [[CSC/ECE 517 Fall 2007/wiki3 6 pm|Controller pattern]]
** [[CSC/ECE 517 Fall 2007/wiki3 6 rs|Controller pattern]]
** [[CSC/ECE 517 Fall 2007/wiki3 6 ub|Controller pattern]]
** [[CSC/ECE 517 Fall 2007/wiki3 7 cl|Bertrand Meyer's patterns]]
** [[CSC/ECE 517 Summer 2008/wiki3 8 jb|Bertrand Meyer's principles]]
** [[CSC/ECE 517 Summer 2008/wiki3 8 smr|Bertrand Meyer's principles]]
** [[CSC/ECE 517 Fall 2007/wiki3 8 42|Bob Martin's principles]]
** [[CSC/ECE 517 Fall 2007/wiki3 8 as|Bob Martin's principles]]
** [[CSC/ECE 517 Fall 2007/wiki3 8 ss|Bob Martin's principles]]
** [[CSC/ECE 517 Summer 2008/wiki1 4 wm|Java vs. Ruby threads]]
** [[CSC/ECE 517 Summer 2008/wiki2 1 mf|Rails vs. PHP]]
** [[CSC/ECE 517 Summer 2008/wiki2 1 n1|Rails vs. PHP]]
** [[CSC/ECE 517 Summer 2008/wiki2 1 tm|Rails vs. PHP]]
** [[CSC/ECE 517 Summer 2008/wiki2 Assignment|Links to best versions of(?) PR 2 pages]]
** [[CSC/ECE 517 Summer 2008/wiki3 1 PF|Pure fabrication pattern]]
** [[CSC/ECE 517 Summer 2008/wiki3 5 rp|Pure fabrication pattern]]
** [[CSC/ECE 517 Summer 2008/wiki3 2 acmoore2|Patterns almanac: State, Basic Relationship, Manager]]
** [[CSC/ECE 517 Summer 2008/wiki3 2 mb|Patterns almanac: Object pool, Producer-consumer, Immutable, Web site review]]
** [[CSC/ECE 517 Summer 2008/wiki3 6 esb|Protected variation]]
** [[CSC/ECE 517 Summer 2008/wiki3 Assignment|Links to best versions of(?) PR 3 pages]]

Latest revision as of 22:29, 22 July 2009

Summary of pages done in Fall 2007 and Summer 2008