`
jlaky
  • 浏览: 42852 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论
文章列表
  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 ...
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 ...
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, " ...
  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 ...
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 ...
  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 ...
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 ...
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 ...
Engel是一个爬虫项目,昨天做了一天,弄了个简要版本,我放在了ruby forge上。 工作了两三年了,其实一直以来的兴趣是互联网搜索和挖掘,以前主要在大学的实验室做这些事儿,用Java倒腾了不少事儿,由于一直心愿未了,决定从基础框架开始,用Ruby重新做一个。持续会有一系列的项目:    爬虫框架  分词  索引、搜索框架  Web分析和信息抽取  基于文本的研发:分类,聚类,相关性 我要找回兴趣和梦想~    
  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 ...
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 ...
  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. ...
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 ...
Global site tag (gtag.js) - Google Analytics