SlideShare uma empresa Scribd logo
1 de 70
Baixar para ler offline
Objects, Objects
 Everywhere
    Mike Pack
     @zombidev
Let’s Talk Objects

  Behavior
     +
   State
Let’s Talk Objects
         Behavior

I’m a person, what can I do?
            Walk
            Talk
            Eat

 Could also be defined as:
          Move Legs
          Move Lips
         Ingest Food
Let’s Talk Objects
                 Behavior




Level of abstraction matters!
  Behavioral abstraction varies per domain.
Let’s Talk Objects
              State

I’m a person, who am I currently?
            Mike Pack
              Male
             Brown

  Therefore, I have attributes:
             Name
             Gender
            Hair Color
Let’s Talk Objects
              State



     States change
When I’m 70, my attributes might be:

            Mike Pack
              Male
              Grey
Let’s Talk Objects

 Behavior changes too!
I just learned to jump, now my behavior is:

                  Walk
                   Talk
                   Eat
                  Jump
Let’s Talk Objects

  Behavior
     +
   State
HTML

<div id=”name”>
  Mike
</div>
  Is this an object?
Attribute
       HTML         Name
<div id=”name”>
  Mike
</div>
  Is this an object?
Attribute
       HTML         Name
<div id=”name”>
  Mike
           State
</div>
  Is this an object?
Attribute
        HTML         Name
<div id=”name”>
  Mike the beef?
Where’s    State
</div>
   Is this an object?
Attribute
         HTML         Name
  <div id=”name”>
    Mike behavior?
Where’s the State
  </div>
    Is this an object?
HTML
<div id=”name”
   onclick=”...”>
  Mike
</div>
  Is this an object?
Attribute
       HTML         Name
<div id=”name”
   onclick=”...”>
  Mike      Behavior!
</div> State
  Is this an object?
HTML


               HTML is object oriented
                                (albeit, not for purist)




HTML does not exhibit other properties of an OO systems:
- Inheritance
- Polymorphism
- etc
HTML


         Don’t use onclick=”...”
However, without onclick, HTML does not exhibit behavior.
CSS

a{
  color: red;
}
 Is this an object?
CSS
        Attribute
a{       Name

  color: red;
}
 Is this an object?
CSS
        Attribute
a{       Name

  color: red;
}             State

 Is this an object?
CSS
          Attribute
 a{        Name

   color:the beef?
Where’s   red;
 }             State

   Is this an object?
CSS
a{
  color: red;
  &:hover {
    color: blue;
  }
}
Is this an object?
Attribute     CSS
 Name a {
          color: red; Behavior!
          &:hover {
            color: blue;
          }
                           State
      }
      Is this an object?
CSS
       a{
Behavior color: red;     State
         &:hover {      Change
           color: blue;
         }
       }
   Behavior changes state.
CSS


                  CSS is object oriented
                                      (not for purist)




CSS does not exhibit other properties of an OO systems:
- Inheritance
- Polymorphism
- etc
JavaScript
var book = {
 title: “The Art of
         War”
};
   Is this an object?
Attribute
 Name
            JavaScript
    var book = {
     title: “The Art of
             War”
    };
        Is this an object?
Attribute
 Name
            JavaScript
    var book = {
     title: “The Art of
             War” State
    };
        Is this an object?
Attribute
 Name
            JavaScript
   var book = {
    title: “The Art of
   Where’s the beef?
            War” State
   };
        Is this an object?
Attribute
 Name
            JavaScript
   var book = {
    title: “The Art of
   Where’s the beef?
          It’sWar”
              implicit! State
   };
        Is this an object?
JavaScript
var book = {
 title: “The Art of War”,
 constructor: function() {...},
 hasOwnProperty: function() {...},
 ...
};

      Implicit behavior.
JavaScript


JavaScript is object oriented
           (of course)
JavaScript


It’s not entirely object oriented
    JavaScript has primitives, too.
JavaScript


If it’s an object, typeof knows
   typeof {} === ‘object’ //=> true
JavaScript


Integers are not objects
typeof 1 === ‘object’ //=> false
JavaScript


  undefined is not an object
typeof undefined === ‘object’ //=> false
JavaScript


Literals are not always primitives
     typeof [] === ‘object’ //=> true
JavaScript

  typeof might not return object
     typeof true === ‘object’ //=> false
    typeof true === ‘boolean’ //=> true
         But booleans are objects!
new Boolean(1).valueOf() === true //=> true
JavaScript


Careful, typeof can bite
typeof null === ‘object’ //=> true
     new Null() //=> error
Ruby


       1

Is this an object?
Ruby        State
              (accessor)
     1
1.real #=> 1

Is this an object?
Ruby        State
              (accessor)
     1
1.real #=> 1
1 + 1 #=> 2
Is this an object?
Ruby        State
              1     (accessor)
       1.real #=> 1
Behavior 1 + 1 #=> 2
        1.+(1) #=> 2
      Is this an object?
Ruby


Ruby is object oriented
Ruby


Everything is an object
Ruby


Literal arrays are new objects
  [].object_id #=> 70318249770140
  [].object_id #=> 70318249594160
Ruby


Literal strings are new objects
‘slurpy’.object_id #=> 70318249561400
‘slurpy’.object_id #=> 70318249500340
Ruby


Literal hashes are new objects
   {}.object_id #=> 7019206373870
  {}.object_id #=> 70192063701240
Ruby


Literal regexs are new objects
  //.object_id #=> 70192063385520
  //.object_id #=> 70192067965040
Ruby


Literal ranges are new objects
 (1..2).object_id #=> 70192067946460
 (1..2).object_id #=> 70192067921120
Ruby


 Not everything creates a new
            object
Ruby has singleton objects (objects instantiated once).
Ruby


nil is a singleton
 nil.object_id #=> 4
 nil.object_id #=> 4
Ruby

booleans are singletons
   false.object_id #=> 0
   false.object_id #=> 0
    true.object_id #=> 2
    true.object_id #=> 2
Ruby


Numbers are singletons
    1.object_id #=> 3
    1.object_id #=> 3
Ruby

     um s
  xn
Fi Numbers are singletons
        1.object_id #=> 3
        1.object_id #=> 3
Ruby

Bignums are not singletons
4611686018427387904.object_id #=>
        70192063730740
4611686018427387904.object_id #=>
        70192063508580
Ruby

  Bignums are not singletons
 4611686018427387904.object_id #=>
         70192063730740
 4611686018427387904.object_id #=>
         70192063508580


Why 4611686018427387904?
bytes to store
               Ruby       integer
bytes = 0.size #=> 8
bytes to store
                Ruby          integer
bytes = 0.size #=> 8
                          8 bits per byte

bits = bytes * 8 #=> 64
                          64 bit machine
bytes to store
                Ruby          integer
bytes = 0.size #=> 8
                          8 bits per byte

bits = bytes * 8 #=> 64
                          64 bit machine

                        1 bit for sign
                       + 1 bit for Ruby
2 ** (bits - 2) #=>
4611686018427387904
Ruby
 4611686018427387904
         Bignum
     Different objects.


4611686018427387904 - 1
          Fixnum
      Singleton object.
Ruby

Why does nil have object_id of 4?

     1 have object_id of 3?

    true have object_id of 2?
Ruby
Because Matz says so
  false.object_id #=> 0
      0.object_id #=> 1
   true.object_id #=> 2
      1.object_id #=> 3
     nil.object_id #=> 4
      2.object_id #=> 5
Ruby
   Find by object_id
ObjectSpace._id2ref(0) #=> false
ObjectSpace._id2ref(1) #=> 0
ObjectSpace._id2ref(2) #=> true
ObjectSpace._id2ref(3) #=> 1
ObjectSpace._id2ref(4) #=> nil
ObjectSpace._id2ref(5) #=> 2
ObjectSpace._id2ref(6) #=> error
ObjectSpace._id2ref(7) #=> 3
ObjectSpace._id2ref(8) #=> error
Ruby

Negative object_ids
  -1.object_id #=> -1
  -2.object_id #=> -3
  -3.object_id #=> -5
Objects.useful? # => true
Objects.useful? # => true
Consistent modeling across the stack.
Objects.useful? # => true
Helpful in representing the real world.
Objects.useful? # => true
     Fun and expressive.
Thanks!
@zombidev

Mais conteúdo relacionado

Mais procurados

Mais procurados (8)

Jazoon 2010 - Building DSLs with Eclipse
Jazoon 2010 - Building DSLs with EclipseJazoon 2010 - Building DSLs with Eclipse
Jazoon 2010 - Building DSLs with Eclipse
 
Json
JsonJson
Json
 
Introduction to JRuby
Introduction to JRubyIntroduction to JRuby
Introduction to JRuby
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
Ruby objects
Ruby objectsRuby objects
Ruby objects
 
jQuery
jQueryjQuery
jQuery
 
jQuery
jQueryjQuery
jQuery
 
03 Object Relational Mapping
03 Object Relational Mapping03 Object Relational Mapping
03 Object Relational Mapping
 

Semelhante a Objects, Objects Everywhere

NinjaScript and Mizugumo 2011-02-05
NinjaScript and Mizugumo 2011-02-05NinjaScript and Mizugumo 2011-02-05
NinjaScript and Mizugumo 2011-02-05lrdesign
 
みゆっき☆Think#7 「本気で学ぶJavascript」
みゆっき☆Think#7 「本気で学ぶJavascript」みゆっき☆Think#7 「本気で学ぶJavascript」
みゆっき☆Think#7 「本気で学ぶJavascript」techtalkdwango
 
第7回みゆっき☆Think 本気で学ぶ JavaScript
第7回みゆっき☆Think 本気で学ぶ JavaScript第7回みゆっき☆Think 本気で学ぶ JavaScript
第7回みゆっき☆Think 本気で学ぶ JavaScriptTakuya Fujimura
 
Javascript Objects Deep Dive
Javascript Objects Deep DiveJavascript Objects Deep Dive
Javascript Objects Deep DiveManish Jangir
 
Art of Javascript
Art of JavascriptArt of Javascript
Art of JavascriptTarek Yehia
 
Things that every JavaScript developer should know by Rachel Appel at FrontCo...
Things that every JavaScript developer should know by Rachel Appel at FrontCo...Things that every JavaScript developer should know by Rachel Appel at FrontCo...
Things that every JavaScript developer should know by Rachel Appel at FrontCo...DevClub_lv
 
Understanding PHP objects
Understanding PHP objectsUnderstanding PHP objects
Understanding PHP objectsjulien pauli
 
Symfony & Javascript. Combining the best of two worlds
Symfony & Javascript. Combining the best of two worldsSymfony & Javascript. Combining the best of two worlds
Symfony & Javascript. Combining the best of two worldsIgnacio Martín
 
React JS and why it's awesome
React JS and why it's awesomeReact JS and why it's awesome
React JS and why it's awesomeAndrew Hull
 
Interesting Facts About Javascript
Interesting Facts About JavascriptInteresting Facts About Javascript
Interesting Facts About JavascriptManish Jangir
 
Evan Schultz - Angular Summit - 2016
Evan Schultz - Angular Summit - 2016Evan Schultz - Angular Summit - 2016
Evan Schultz - Angular Summit - 2016Evan Schultz
 
The Ruby Racer: under the hood
The Ruby Racer: under the hoodThe Ruby Racer: under the hood
The Ruby Racer: under the hoodcowboyd
 
WDB005.1 - JavaScript for Java Developers (Lecture 1)
WDB005.1 - JavaScript for Java Developers (Lecture 1)WDB005.1 - JavaScript for Java Developers (Lecture 1)
WDB005.1 - JavaScript for Java Developers (Lecture 1)Igor Khotin
 
Practical Ruby Projects (Alex Sharp)
Practical Ruby Projects (Alex Sharp)Practical Ruby Projects (Alex Sharp)
Practical Ruby Projects (Alex Sharp)MongoSF
 
Practical Ruby Projects with MongoDB - MongoSF
Practical Ruby Projects with MongoDB - MongoSFPractical Ruby Projects with MongoDB - MongoSF
Practical Ruby Projects with MongoDB - MongoSFAlex Sharp
 
Reasons To Love Ruby
Reasons To Love RubyReasons To Love Ruby
Reasons To Love RubyBen Scheirman
 

Semelhante a Objects, Objects Everywhere (20)

NinjaScript and Mizugumo 2011-02-05
NinjaScript and Mizugumo 2011-02-05NinjaScript and Mizugumo 2011-02-05
NinjaScript and Mizugumo 2011-02-05
 
みゆっき☆Think#7 「本気で学ぶJavascript」
みゆっき☆Think#7 「本気で学ぶJavascript」みゆっき☆Think#7 「本気で学ぶJavascript」
みゆっき☆Think#7 「本気で学ぶJavascript」
 
第7回みゆっき☆Think 本気で学ぶ JavaScript
第7回みゆっき☆Think 本気で学ぶ JavaScript第7回みゆっき☆Think 本気で学ぶ JavaScript
第7回みゆっき☆Think 本気で学ぶ JavaScript
 
Javascript Objects Deep Dive
Javascript Objects Deep DiveJavascript Objects Deep Dive
Javascript Objects Deep Dive
 
Art of Javascript
Art of JavascriptArt of Javascript
Art of Javascript
 
Things that every JavaScript developer should know by Rachel Appel at FrontCo...
Things that every JavaScript developer should know by Rachel Appel at FrontCo...Things that every JavaScript developer should know by Rachel Appel at FrontCo...
Things that every JavaScript developer should know by Rachel Appel at FrontCo...
 
Understanding PHP objects
Understanding PHP objectsUnderstanding PHP objects
Understanding PHP objects
 
Symfony & Javascript. Combining the best of two worlds
Symfony & Javascript. Combining the best of two worldsSymfony & Javascript. Combining the best of two worlds
Symfony & Javascript. Combining the best of two worlds
 
React JS and why it's awesome
React JS and why it's awesomeReact JS and why it's awesome
React JS and why it's awesome
 
Javascript
JavascriptJavascript
Javascript
 
"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues
 
Ruby Classes
Ruby ClassesRuby Classes
Ruby Classes
 
Interesting Facts About Javascript
Interesting Facts About JavascriptInteresting Facts About Javascript
Interesting Facts About Javascript
 
Evan Schultz - Angular Summit - 2016
Evan Schultz - Angular Summit - 2016Evan Schultz - Angular Summit - 2016
Evan Schultz - Angular Summit - 2016
 
The Ruby Racer: under the hood
The Ruby Racer: under the hoodThe Ruby Racer: under the hood
The Ruby Racer: under the hood
 
WDB005.1 - JavaScript for Java Developers (Lecture 1)
WDB005.1 - JavaScript for Java Developers (Lecture 1)WDB005.1 - JavaScript for Java Developers (Lecture 1)
WDB005.1 - JavaScript for Java Developers (Lecture 1)
 
Practical Ruby Projects (Alex Sharp)
Practical Ruby Projects (Alex Sharp)Practical Ruby Projects (Alex Sharp)
Practical Ruby Projects (Alex Sharp)
 
Practical Ruby Projects with MongoDB - MongoSF
Practical Ruby Projects with MongoDB - MongoSFPractical Ruby Projects with MongoDB - MongoSF
Practical Ruby Projects with MongoDB - MongoSF
 
Reasons To Love Ruby
Reasons To Love RubyReasons To Love Ruby
Reasons To Love Ruby
 
Javascript
JavascriptJavascript
Javascript
 

Último

08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
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.pdfsudhanshuwaghmare1
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
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 organizationRadu Cotescu
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
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 WorkerThousandEyes
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 

Último (20)

08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
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
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
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
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 

Objects, Objects Everywhere

  • 1. Objects, Objects Everywhere Mike Pack @zombidev
  • 2. Let’s Talk Objects Behavior + State
  • 3. Let’s Talk Objects Behavior I’m a person, what can I do? Walk Talk Eat Could also be defined as: Move Legs Move Lips Ingest Food
  • 4. Let’s Talk Objects Behavior Level of abstraction matters! Behavioral abstraction varies per domain.
  • 5. Let’s Talk Objects State I’m a person, who am I currently? Mike Pack Male Brown Therefore, I have attributes: Name Gender Hair Color
  • 6. Let’s Talk Objects State States change When I’m 70, my attributes might be: Mike Pack Male Grey
  • 7. Let’s Talk Objects Behavior changes too! I just learned to jump, now my behavior is: Walk Talk Eat Jump
  • 8. Let’s Talk Objects Behavior + State
  • 9. HTML <div id=”name”> Mike </div> Is this an object?
  • 10. Attribute HTML Name <div id=”name”> Mike </div> Is this an object?
  • 11. Attribute HTML Name <div id=”name”> Mike State </div> Is this an object?
  • 12. Attribute HTML Name <div id=”name”> Mike the beef? Where’s State </div> Is this an object?
  • 13. Attribute HTML Name <div id=”name”> Mike behavior? Where’s the State </div> Is this an object?
  • 14. HTML <div id=”name” onclick=”...”> Mike </div> Is this an object?
  • 15. Attribute HTML Name <div id=”name” onclick=”...”> Mike Behavior! </div> State Is this an object?
  • 16. HTML HTML is object oriented (albeit, not for purist) HTML does not exhibit other properties of an OO systems: - Inheritance - Polymorphism - etc
  • 17. HTML Don’t use onclick=”...” However, without onclick, HTML does not exhibit behavior.
  • 18. CSS a{ color: red; } Is this an object?
  • 19. CSS Attribute a{ Name color: red; } Is this an object?
  • 20. CSS Attribute a{ Name color: red; } State Is this an object?
  • 21. CSS Attribute a{ Name color:the beef? Where’s red; } State Is this an object?
  • 22. CSS a{ color: red; &:hover { color: blue; } } Is this an object?
  • 23. Attribute CSS Name a { color: red; Behavior! &:hover { color: blue; } State } Is this an object?
  • 24. CSS a{ Behavior color: red; State &:hover { Change color: blue; } } Behavior changes state.
  • 25. CSS CSS is object oriented (not for purist) CSS does not exhibit other properties of an OO systems: - Inheritance - Polymorphism - etc
  • 26. JavaScript var book = { title: “The Art of War” }; Is this an object?
  • 27. Attribute Name JavaScript var book = { title: “The Art of War” }; Is this an object?
  • 28. Attribute Name JavaScript var book = { title: “The Art of War” State }; Is this an object?
  • 29. Attribute Name JavaScript var book = { title: “The Art of Where’s the beef? War” State }; Is this an object?
  • 30. Attribute Name JavaScript var book = { title: “The Art of Where’s the beef? It’sWar” implicit! State }; Is this an object?
  • 31. JavaScript var book = { title: “The Art of War”, constructor: function() {...}, hasOwnProperty: function() {...}, ... }; Implicit behavior.
  • 32. JavaScript JavaScript is object oriented (of course)
  • 33. JavaScript It’s not entirely object oriented JavaScript has primitives, too.
  • 34. JavaScript If it’s an object, typeof knows typeof {} === ‘object’ //=> true
  • 35. JavaScript Integers are not objects typeof 1 === ‘object’ //=> false
  • 36. JavaScript undefined is not an object typeof undefined === ‘object’ //=> false
  • 37. JavaScript Literals are not always primitives typeof [] === ‘object’ //=> true
  • 38. JavaScript typeof might not return object typeof true === ‘object’ //=> false typeof true === ‘boolean’ //=> true But booleans are objects! new Boolean(1).valueOf() === true //=> true
  • 39. JavaScript Careful, typeof can bite typeof null === ‘object’ //=> true new Null() //=> error
  • 40. Ruby 1 Is this an object?
  • 41. Ruby State (accessor) 1 1.real #=> 1 Is this an object?
  • 42. Ruby State (accessor) 1 1.real #=> 1 1 + 1 #=> 2 Is this an object?
  • 43. Ruby State 1 (accessor) 1.real #=> 1 Behavior 1 + 1 #=> 2 1.+(1) #=> 2 Is this an object?
  • 46. Ruby Literal arrays are new objects [].object_id #=> 70318249770140 [].object_id #=> 70318249594160
  • 47. Ruby Literal strings are new objects ‘slurpy’.object_id #=> 70318249561400 ‘slurpy’.object_id #=> 70318249500340
  • 48. Ruby Literal hashes are new objects {}.object_id #=> 7019206373870 {}.object_id #=> 70192063701240
  • 49. Ruby Literal regexs are new objects //.object_id #=> 70192063385520 //.object_id #=> 70192067965040
  • 50. Ruby Literal ranges are new objects (1..2).object_id #=> 70192067946460 (1..2).object_id #=> 70192067921120
  • 51. Ruby Not everything creates a new object Ruby has singleton objects (objects instantiated once).
  • 52. Ruby nil is a singleton nil.object_id #=> 4 nil.object_id #=> 4
  • 53. Ruby booleans are singletons false.object_id #=> 0 false.object_id #=> 0 true.object_id #=> 2 true.object_id #=> 2
  • 54. Ruby Numbers are singletons 1.object_id #=> 3 1.object_id #=> 3
  • 55. Ruby um s xn Fi Numbers are singletons 1.object_id #=> 3 1.object_id #=> 3
  • 56. Ruby Bignums are not singletons 4611686018427387904.object_id #=> 70192063730740 4611686018427387904.object_id #=> 70192063508580
  • 57. Ruby Bignums are not singletons 4611686018427387904.object_id #=> 70192063730740 4611686018427387904.object_id #=> 70192063508580 Why 4611686018427387904?
  • 58. bytes to store Ruby integer bytes = 0.size #=> 8
  • 59. bytes to store Ruby integer bytes = 0.size #=> 8 8 bits per byte bits = bytes * 8 #=> 64 64 bit machine
  • 60. bytes to store Ruby integer bytes = 0.size #=> 8 8 bits per byte bits = bytes * 8 #=> 64 64 bit machine 1 bit for sign + 1 bit for Ruby 2 ** (bits - 2) #=> 4611686018427387904
  • 61. Ruby 4611686018427387904 Bignum Different objects. 4611686018427387904 - 1 Fixnum Singleton object.
  • 62. Ruby Why does nil have object_id of 4? 1 have object_id of 3? true have object_id of 2?
  • 63. Ruby Because Matz says so false.object_id #=> 0 0.object_id #=> 1 true.object_id #=> 2 1.object_id #=> 3 nil.object_id #=> 4 2.object_id #=> 5
  • 64. Ruby Find by object_id ObjectSpace._id2ref(0) #=> false ObjectSpace._id2ref(1) #=> 0 ObjectSpace._id2ref(2) #=> true ObjectSpace._id2ref(3) #=> 1 ObjectSpace._id2ref(4) #=> nil ObjectSpace._id2ref(5) #=> 2 ObjectSpace._id2ref(6) #=> error ObjectSpace._id2ref(7) #=> 3 ObjectSpace._id2ref(8) #=> error
  • 65. Ruby Negative object_ids -1.object_id #=> -1 -2.object_id #=> -3 -3.object_id #=> -5
  • 67. Objects.useful? # => true Consistent modeling across the stack.
  • 68. Objects.useful? # => true Helpful in representing the real world.
  • 69. Objects.useful? # => true Fun and expressive.