LoginSignup
4
4

More than 5 years have passed since last update.

【プログラミング48(/2 -1)手】Prototype

Posted at

ポイント

Prototypeパターン。
原型となるインスタンスをコピーして新しいインスタンスを生成するためのパターン。

サンプルコード

rubyだと、もともとのObject Classにcloneとか、dupメソッドがあるので割愛。

Prototype.rb
class Hoge
    def initialize(name)
        @name = name
    end
end

a = Hoge.new('original object')
b = a.clone
puts a.inspect
puts b.inspect

所感

  • まあデザインパターン作られた当時はあれだったのかもしれないけど、
    デザインパターンではないきがする。。

参考

http://www.ie.u-ryukyu.ac.jp/~e085739/java.it.4.html
http://docs.ruby-lang.org/ja/1.9.3/class/Object.html

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4