- 浏览: 42852 次
- 性别:
- 来自: 上海
最新评论
-
aking86:
大哥,可不可以搞个DEMO出来。这个更管用。道理咱懂,搞出来有 ...
Mapper -
happyking:
可以考虑下nosql来实现,一些知名的SNS都是用NOSQL实 ...
SNS网站feed的设计思考 -
boobmoom:
请问,去IBM以后做的还是ruby 和 rails 吗?
Work@IBM -
chennanfei:
你在哪个部门哪个team?做dev?
Work@IBM -
chennanfei:
有必要给每一个好友创建一条feed记录吗?考虑到用户可以删除好 ...
SNS网站feed的设计思考
文章列表
has_many has_one belongs_to都有设置dependent属性
has_many的文档里写的dependent是设置为:destroy将调用关联对象destroy方法,如果设置为:delete_all将调用class.delete_all而不调用destroy方法,:nullify就是直接将外键设为null.
has_one的文档里写的dependent是设置为:destroy将调用关联对象destroy方法,如果设置为:delete将调用class.delete而不调用destroy方法,:nullify就是直接将外键设为null.
belo ...
- 2009-06-08 11:47
- 浏览 2163
- 评论(0)
Singleton is common for every coder. It provide only instance of class.
class SimpleLogger
# Lots of code deleted...
@@instance = SimpleLogger.new
def self.instance
return @@instance
end
private_class_method :new
end
In ruby we can use Singleton Module, it is lazy inst ...
- 2009-06-07 22:33
- 浏览 874
- 评论(0)
The Decorator pattern is used when you need to add some feature to a class with wrapper rather than write a new method.
Think about the writer support chechsum write, line number write:
class EnhancedWriter
attr_reader :check_sum
def initialize(path)
@file = File.open(path, " ...
- 2009-06-06 19:56
- 浏览 1138
- 评论(0)
When we meet these requirements:
1) Controlling access to an object
2) providing a location-independent way of getting at the object
3) delaying its creation
all three actually have a common solution: the Proxy pattern.
Code First:
class BankAccount
attr_reader :balance
def ...
- 2009-06-06 16:20
- 浏览 915
- 评论(0)
The Adapter is just like the power adapter such as from 220V to 120V. And when the pin does not fit the socket we need the adapter to fit it.
In software system, we already have a Encrypter to encrypt file:
class Encrypter
def initialize(key)
@key = key
end
def encrypt(reader, writ ...
- 2009-06-06 12:34
- 浏览 869
- 评论(0)
Command pattern command is an instruction to do something, something specific. It can be execute right now or later or specific time. In our GUI's do and undo actions it is wildly used.
If we have a Button base class:
class SlickButton
#
# Lots of button drawing and management
...
- 2009-06-05 12:46
- 浏览 925
- 评论(0)
The Iterator pattern is a technique that allows an aggregate object to provide the outside world with a way to access its collection of subobjects.
In Java we use java.util.Iterator interface to be implemented.
eg. StringTokenizer ResultSet
In Ruby We can write Iterator:
class ArrayIterator
...
- 2009-06-03 22:31
- 浏览 855
- 评论(0)
When we want to build up bigger objects from small sub-objects those build up on the sub-sub-objects then there is a Composite Pattern.
The key point of the pattern is that complex objects and simple objects are treated the same way.
The GoF called the design pattern for our “the sum acts like o ...
- 2009-06-01 15:39
- 浏览 864
- 评论(0)
Engel是一个爬虫项目,昨天做了一天,弄了个简要版本,我放在了ruby forge上。
工作了两三年了,其实一直以来的兴趣是互联网搜索和挖掘,以前主要在大学的实验室做这些事儿,用Java倒腾了不少事儿,由于一直心愿未了,决定从基础框架开始,用Ruby重新做一个。持续会有一系列的项目:
爬虫框架
分词
索引、搜索框架
Web分析和信息抽取
基于文本的研发:分类,聚类,相关性
我要找回兴趣和梦想~
- 2009-05-31 09:12
- 浏览 854
- 评论(0)
The Observer Pattern is useful when you need to inform other objects whenever one original change of object occurs. Such as SNS feeds feature, cache clear and so on...
Without this pattern the code will looks like below:
class Payroll
def update( changed_employee )
puts("Cut a n ...
- 2009-05-29 10:40
- 浏览 881
- 评论(0)
The Template method is build around inheritance, the inheritance has the nature born relationship.
So the Strategy give a delegate solution.
So we use the strategy implementation:
class Formatter
def output_report( title, text )
raise 'Abstract method called'
end
end
class HTMLF ...
- 2009-05-28 11:55
- 浏览 777
- 评论(0)
The following tips are really essential
the patterns for patterns:
1) Seperate out the things that change from those stay the
same
A key goal of software engineering is to builld a system that allow us to
contain the damage.
To make all changes local rather than change them everywhere. ...
- 2009-05-27 13:02
- 浏览 862
- 评论(0)
When we have a complex algorithm including several steps to build something, which would be vary in the middle.Now you need Template method.It comes up with an example:
class Report
def initialize
@title = 'Monthly Report'
@text = [ 'Things are going', 'really, really well.' ]
end
...
- 2009-05-27 12:51
- 浏览 810
- 评论(0)