НАСЛЕДОВАНИЕ АВТОМАТНЫХ КЛАССОВ С ИСПОЛЬЗОВАНИЕМ ДИНАМИЧЕСКИХ ЯЗЫКОВ ПРОГРАММИРОВАНИЯ (НА ПРИМЕРЕ ЯЗЫКА RUBY)

  • Published on
    05-Apr-2017

  • View
    217

  • Download
    4

Embed Size (px)

Transcript

  • 4, 2009 21

    681.3.06

    ( RUBY)

    . . , DataArt. . ,. . , . , - ,

    - . - .

    - , , - .

    - - . , 2008 . 40 % [1]. - - -, [2]. Ruby 2008 . [1]. , , - Ruby on Rails [3], Open Source--. - - (, - Ruby on Rails). - Restful-authentication [4], - - . 96 % [5] Ruby on Rails .

    - Acts as State Machine [6], - - . , , - . [2] , - State Ma-chine on Steroids. -- , , - . , , Restful-authentication.

    - - Restful-authentication.

    UML 2 [7],

  • 4, 200922

    - , [8], UML 2 - .

    - (. 1) - SampleUser, - BasicUser, :

    deleted, blocked, deleted. blocked ;

    activation captcha. - deleted;

    suspended, activation.

    Restful-authentication -. , , - -:

    1) ;2) ;3) , -

    . , -

    , - .

    , .

    (BasicUser), . 2 , activation suspended deleted. activation -

    : passive, active pending, .

    -:

    delete ;suspend

    :

    ;

    ;

    .1.

    .2.

    .3.

    AdvancedUser : BasicUser

    pendingenter MAC

    suspended

    activation

    deleted

    deletedblockedremove

    delete

    activedenter DA

    active

    captcha

    activate

    registered

    register

    activate

    unsuspend [guard ]

    BasicUser

    unsuspend

    guard

    suspend

    delete

    activateregister [guard]

    passive

    pendingenter MAC

    activeenter DA

    suspended

    deletedenter DD

    activation

    guard

    SampleUser : BasicUser

    suspended

    activation

    deleted

    deletedblockedremovedelete

    activedenter DA

    captcha

    activate

    unsuspend

  • 4, 2009 23

    register , ;

    activate ;

    unsuspend - -.

    AdvancedUser (. 3) - BasicUser -.

    1. : Captcha ( - ) - .

    active.2. -

    : , , , .

    deleted.

    Acts as State Machine

    (Basic-User) Restful-authentication - Acts as State Machine. :

    acts_as_state_machine :initial - ;

    state . - - [2] - ;

    event ;transitions , -

    -

    . - , - .

    . - BasicUser, - . 4.

    Ruby, :class BasicUser

    acts_as_state_machine :initial => :pending

    state :passive state :pending, :enter => :make_activation_code state :active, :enter => :do_activate state :suspended state :deleted, :enter => :do_delete

    event :register do transitions :from => :passive, :to => :pending, :guard => Proc.new {|u| !(u.crypted_password.blank? && u.password.blank?) } end

    event :activate do transitions :from => :pending, :to => :active end

    event :suspend do transitions :from => [:passive, :pending, :active],:to => :suspended end event :delete do transitions :from => [:passive, :pending, :active,:suspended], :to => :deleted end

    event :unsuspend do transitions :from => :suspended, :to => :active, :guard => Proc.new {|u|!u.activated_at.blank? } transitions :from => :suspended, :to => :pending, :guard => Proc.new {|u|!u.activation_code.blank? } transitions :from => :suspended, :to => :passive endend

    AdvancedUser (. 5), - BasicUser. - Basic-User, Acts as State Machine. - , - BasicUser AdvancedUser .

    , -:class AdvancedUser < BasicUser

    state :captcha state :registered state :blocked

    .4.

    suspended

    BasicUser

    unsuspend unsuspend [ ]

    activateregister [guard]

    unsuspend [guard]

    suspend

    passive pendingenter MACactive

    enter DA

    deletedenter DD

    deletedelete

    suspend

    suspend

    delete

    guard

  • 4, 200924

    event :activate do transitions :from => :captcha, :to => :actived transitions :from => :pending, :to => :captcha end

    event :register do transitions :from => :activated, :to => :registered end

    event :unsuspend do transitions :from => :unsuspend, :to => :captcha end

    event :suspend do transitions :from => [:passive, :pending, :active,:suspended, :captcha, :registered], :to => :suspended end

    event :delete do transitions :from => [:passive, :pending, :active,:suspended, :captcha, :registered], :to => :deleted endend

    : ,

    ;

    , .

    State Machine on Steroids

    - State Machine on Steroids. - . ,

    Acts as State Ma-chine, :

    automaton - , DSL-- (Domain Specific Language) [2];

    group -.

    , . 2:class BasicUser

    include StateMachineOnSteroids

    automaton :user, :initial => :activation do state :deleted

    group :activation, initial => :pending do state :pending do transition :activate, :to => :actived end

    state :passive do transition :register, :to => :pending, :guard => Proc.new {|u|!(u.crypted_password.blank? && u.password.blank?) } end

    state :activated

    transition :suspend, :to => :suspended transition :delete, :to => :deleted end

    state :suspended do event :unsuspend do transition :to => :active, :guard => Proc.new {|u| !u.activated_at.blank? } transition :to => :pending, :guard => Proc.new {|u| !u.activation_code.blank? }

    transition :to => :passive end end endend

    State Machine on Steroids . - - BasicUser.

    AdvancedUser (. . 3):class AdvancedUser < BasicUser

    automaton :user do group :deleted, initial => :blocked do state :blocked do transition :remove, :to => :deleted end

    state :user::activation::deleted end

    group :activation do group :active, initial => :captcha do state :captcha do transition :activate, :to => :activated

    .5. AdvancedUser

    AdvancedUser

    registeractivate

    suspend

    suspend

    deletedelete

    remove

    unsuspendunsuspend [

    activateregister [guard]

    unsuspend[guard]

    suspend

    passive pendingenter MACactive

    enter DA

    suspended

    deletedenter DD

    deletedelete

    suspend

    delete

    blocked

    captcha registered

    unsuspend[guard]

    unsuspend[guard]

    suspendguard]

  • 4, 2009 25

    end

    state :user::activated do transition :register, :to => :registered end

    state :registered end end

    transition :user::delete, :to => :deleted transition :user::activate, :to => :actived state :suspended do event :user::unsuspend, :to => :active end endend

    State Machine on Steroids - Acts as State Machine:

    . - , , - AdvancedUser::Deleted, - -;

    -, - .

    Acts as State Machine State Machine on Steroids

    State Machine on Steroids - - Ruby, :

    - . -, - ;

    - ;

    , - ;

    -.

    State Machine on Steroids - . , , - , -

    Acts as State Machine - .

    - , . 3, - . , - State Machine on Steroids .

    -. Restful-authentication.

    - . - State Machine on Steroids - .

    , - .

    TIOBE1. . TIOBE Software: Tiobe Index. http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html . ., . ., . . 2. - Ruby: Software Engineering Conference. Russia, 2008. http://www.secr.ru/?pageid=4548& submissionid=5270David H. H.3. Ruby on Rails. http://www.rubyonrails.com/Grant G. 4. Restful Authentication Generator. http://github.com/technoweenie/restful-authentication/tree/masterSzinek P5. . Rails Rumble Observations. P. II: Trends in gem/plugin usage. http://www.rubyrailways.com/rails-rumble-observations-part-ii-trends-in-gempl-ugin-usage/Scott B.6. Acts as State Machine. http://agilewebdevelopment.com/plugins/acts_as_state_machine. Object Management Group. 7. Official UML Specifica-tion. http://www.uml.org/#UML2.0 . ., . . 8. - // -. 2007. 5. . 6274.

    Acts as State Machine

    20 8

    State Machine on Steroids

    9 8 3

Recommended

View more >