SlideShare une entreprise Scribd logo
1  sur  35
Télécharger pour lire hors ligne
Ruby Object Design
Eddie Li (ADZ) 
eddie@visionbundles.com 
http://adz.visionbundles.com 
Github: afunction 
Facebook: /adz.624
A difference between Ruby 
object and other languages
1. syntax omission
Pros 
1. Make your codes more readable to a human. 
(model validation, routes, rspec, view helper) 
Cons 
1. High learning curve for beginners. 
(Easy to misunderstanding)
2. No REAL property 
class/instance variables 
and 
method instead.
attr_accessor / attr_reader / attr_writer
Access via class/instance variable
3. Operator is also a method 
magic!
def + 
def - 
def * 
def / 
def << 
def == 
def ===
4. Open Class
5. Meta-programming 
Generate code … by code
wrapper abstraction behavior
Pros 
1. Split logics to different level and make your business logic clean. 
2. Increase productive. 
3. Follow DRY code principle like there is no limitation.
Cons 
1. Hard to maintain (but it can be solve) 
2. Hard to name variables and methods for abstraction behavior. 
3. Hard to understand abstraction behavior codes from time to time.
class_eval 
define_method 
define_singleton_method
6. module & class 
like PHP Traits 
multi inheritance 
break top down inheritance
a. DRY duplicate method
b. callback when some class included 
“base” means the class that include this module.
It can help you… 
1. Modular behavior 
2. Modular abstraction behavior with meta-programming 
3. Reduce code duplication
Pros 
1. Easy to organize a huge/fat class 
2. Design/extend object flexible
Cons 
1. Hard to read and write unit-test 
(when modules with high dependent context) 
2. Hight learning curve 
3. Easy to misleading
7. skip “private, protected” 
method protection
“send” method will skip “private, protected
combine send and include method with module 
extend class outside without changing exists code.
Live Coding. 
aka Demo!
Q&A 
Thank you.

Contenu connexe

Tendances

Top 10+ Things .NET Developers Should Know About Ruby
Top 10+ Things .NET Developers Should Know About RubyTop 10+ Things .NET Developers Should Know About Ruby
Top 10+ Things .NET Developers Should Know About Ruby
Jeff Cohen
 

Tendances (18)

Mca 4030 programming in java
Mca 4030   programming in javaMca 4030   programming in java
Mca 4030 programming in java
 
Bt0074
Bt0074Bt0074
Bt0074
 
Probable questions for semester exam
Probable questions for semester examProbable questions for semester exam
Probable questions for semester exam
 
Assignment 2
Assignment 2Assignment 2
Assignment 2
 
Coding conventions
Coding conventionsCoding conventions
Coding conventions
 
Object Calisthenics
Object CalisthenicsObject Calisthenics
Object Calisthenics
 
Coding conventions
Coding conventionsCoding conventions
Coding conventions
 
Top 10+ Things .NET Developers Should Know About Ruby
Top 10+ Things .NET Developers Should Know About RubyTop 10+ Things .NET Developers Should Know About Ruby
Top 10+ Things .NET Developers Should Know About Ruby
 
sravan java Session1
sravan java Session1sravan java Session1
sravan java Session1
 
java - oop's in depth journey
java - oop's in depth journeyjava - oop's in depth journey
java - oop's in depth journey
 
Core java programming tutorial - Brainsmartlabs
Core java programming tutorial - BrainsmartlabsCore java programming tutorial - Brainsmartlabs
Core java programming tutorial - Brainsmartlabs
 
core java online training - eglobalsystems
core java online training - eglobalsystemscore java online training - eglobalsystems
core java online training - eglobalsystems
 
Bt0074, oops with java
Bt0074, oops with javaBt0074, oops with java
Bt0074, oops with java
 
Bt0074, oops with java
Bt0074, oops with javaBt0074, oops with java
Bt0074, oops with java
 
Questpond - Top 10 Interview Questions and Answers on OOPS
Questpond - Top 10 Interview Questions and Answers on OOPSQuestpond - Top 10 Interview Questions and Answers on OOPS
Questpond - Top 10 Interview Questions and Answers on OOPS
 
Code like a ninja session 1 object-oriented principles
Code like a ninja  session 1   object-oriented principlesCode like a ninja  session 1   object-oriented principles
Code like a ninja session 1 object-oriented principles
 
PHP - Procedural To Object-Oriented
PHP - Procedural To Object-OrientedPHP - Procedural To Object-Oriented
PHP - Procedural To Object-Oriented
 
C sharp
C sharpC sharp
C sharp
 

Similaire à Ruby Object Design

The View object orientated programming in Lotuscript
The View object orientated programming in LotuscriptThe View object orientated programming in Lotuscript
The View object orientated programming in Lotuscript
Bill Buchan
 
6 Modules Inheritance Gems
6 Modules Inheritance Gems6 Modules Inheritance Gems
6 Modules Inheritance Gems
liahhansen
 

Similaire à Ruby Object Design (20)

Solid principles, Design Patterns, and Domain Driven Design
Solid principles, Design Patterns, and Domain Driven DesignSolid principles, Design Patterns, and Domain Driven Design
Solid principles, Design Patterns, and Domain Driven Design
 
04 inheritance
04 inheritance04 inheritance
04 inheritance
 
C#
C#C#
C#
 
C++ programming introduction
C++ programming introductionC++ programming introduction
C++ programming introduction
 
inheritance
inheritanceinheritance
inheritance
 
Inheritance in java.ppt
Inheritance in java.pptInheritance in java.ppt
Inheritance in java.ppt
 
The View object orientated programming in Lotuscript
The View object orientated programming in LotuscriptThe View object orientated programming in Lotuscript
The View object orientated programming in Lotuscript
 
Php oop (1)
Php oop (1)Php oop (1)
Php oop (1)
 
Writing Readable Code
Writing Readable CodeWriting Readable Code
Writing Readable Code
 
OOP interview questions & answers.
OOP interview questions & answers.OOP interview questions & answers.
OOP interview questions & answers.
 
13 ruby modules
13 ruby modules13 ruby modules
13 ruby modules
 
04 inheritance
04 inheritance04 inheritance
04 inheritance
 
6 Modules Inheritance Gems
6 Modules Inheritance Gems6 Modules Inheritance Gems
6 Modules Inheritance Gems
 
Mca2030 object oriented programming – c++
Mca2030  object oriented programming – c++Mca2030  object oriented programming – c++
Mca2030 object oriented programming – c++
 
What is OOP_ (Object Oriented Programming) (1).pptx
What is OOP_ (Object Oriented Programming) (1).pptxWhat is OOP_ (Object Oriented Programming) (1).pptx
What is OOP_ (Object Oriented Programming) (1).pptx
 
Csci360 20 (1)
Csci360 20 (1)Csci360 20 (1)
Csci360 20 (1)
 
Csci360 20
Csci360 20Csci360 20
Csci360 20
 
Introduction To Doctrine 2
Introduction To Doctrine 2Introduction To Doctrine 2
Introduction To Doctrine 2
 
Unusual C# - OOP
Unusual C# - OOPUnusual C# - OOP
Unusual C# - OOP
 
Reflection in Java
Reflection in JavaReflection in Java
Reflection in Java
 

Dernier

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Dernier (20)

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 

Ruby Object Design