Objects, Objects Everywhere
Upcoming SlideShare
Loading in...5
×
 

Objects, Objects Everywhere

on

  • 593 views

 

Statistics

Views

Total Views
593
Views on SlideShare
592
Embed Views
1

Actions

Likes
0
Downloads
1
Comments
0

1 Embed 1

https://twitter.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Objects, Objects Everywhere Objects, Objects Everywhere Presentation Transcript

    • Objects, Objects Everywhere Mike Pack @zombidev
    • Let’s Talk Objects Behavior + State
    • Let’s Talk Objects BehaviorI’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 BehaviorLevel of abstraction matters! Behavioral abstraction varies per domain.
    • Let’s Talk Objects StateI’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 changeWhen 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.
    • CSSa{ color: red;} Is this an object?
    • CSS Attributea{ Name color: red;} Is this an object?
    • CSS Attributea{ Name color: red;} State Is this an object?
    • CSS Attribute a{ Name color:the beef?Where’s red; } State Is this an object?
    • CSSa{ 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
    • JavaScriptvar 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?
    • JavaScriptvar book = { title: “The Art of War”, constructor: function() {...}, hasOwnProperty: function() {...}, ...}; Implicit behavior.
    • JavaScriptJavaScript is object oriented (of course)
    • JavaScriptIt’s not entirely object oriented JavaScript has primitives, too.
    • JavaScriptIf it’s an object, typeof knows typeof {} === ‘object’ //=> true
    • JavaScriptIntegers are not objectstypeof 1 === ‘object’ //=> false
    • JavaScript undefined is not an objecttypeof undefined === ‘object’ //=> false
    • JavaScriptLiterals 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
    • JavaScriptCareful, typeof can bitetypeof null === ‘object’ //=> true new Null() //=> error
    • Ruby 1Is this an object?
    • Ruby State (accessor) 11.real #=> 1Is this an object?
    • Ruby State (accessor) 11.real #=> 11 + 1 #=> 2Is this an object?
    • Ruby State 1 (accessor) 1.real #=> 1Behavior 1 + 1 #=> 2 1.+(1) #=> 2 Is this an object?
    • RubyRuby is object oriented
    • RubyEverything is an object
    • RubyLiteral arrays are new objects [].object_id #=> 70318249770140 [].object_id #=> 70318249594160
    • RubyLiteral strings are new objects‘slurpy’.object_id #=> 70318249561400‘slurpy’.object_id #=> 70318249500340
    • RubyLiteral hashes are new objects {}.object_id #=> 7019206373870 {}.object_id #=> 70192063701240
    • RubyLiteral regexs are new objects //.object_id #=> 70192063385520 //.object_id #=> 70192067965040
    • RubyLiteral ranges are new objects (1..2).object_id #=> 70192067946460 (1..2).object_id #=> 70192067921120
    • Ruby Not everything creates a new objectRuby has singleton objects (objects instantiated once).
    • Rubynil is a singleton nil.object_id #=> 4 nil.object_id #=> 4
    • Rubybooleans are singletons false.object_id #=> 0 false.object_id #=> 0 true.object_id #=> 2 true.object_id #=> 2
    • RubyNumbers are singletons 1.object_id #=> 3 1.object_id #=> 3
    • Ruby um s xnFi Numbers are singletons 1.object_id #=> 3 1.object_id #=> 3
    • RubyBignums are not singletons4611686018427387904.object_id #=> 701920637307404611686018427387904.object_id #=> 70192063508580
    • Ruby Bignums are not singletons 4611686018427387904.object_id #=> 70192063730740 4611686018427387904.object_id #=> 70192063508580Why 4611686018427387904?
    • bytes to store Ruby integerbytes = 0.size #=> 8
    • bytes to store Ruby integerbytes = 0.size #=> 8 8 bits per bytebits = bytes * 8 #=> 64 64 bit machine
    • bytes to store Ruby integerbytes = 0.size #=> 8 8 bits per bytebits = bytes * 8 #=> 64 64 bit machine 1 bit for sign + 1 bit for Ruby2 ** (bits - 2) #=>4611686018427387904
    • Ruby 4611686018427387904 Bignum Different objects.4611686018427387904 - 1 Fixnum Singleton object.
    • RubyWhy does nil have object_id of 4? 1 have object_id of 3? true have object_id of 2?
    • RubyBecause 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_idObjectSpace._id2ref(0) #=> falseObjectSpace._id2ref(1) #=> 0ObjectSpace._id2ref(2) #=> trueObjectSpace._id2ref(3) #=> 1ObjectSpace._id2ref(4) #=> nilObjectSpace._id2ref(5) #=> 2ObjectSpace._id2ref(6) #=> errorObjectSpace._id2ref(7) #=> 3ObjectSpace._id2ref(8) #=> error
    • RubyNegative object_ids -1.object_id #=> -1 -2.object_id #=> -3 -3.object_id #=> -5
    • Objects.useful? # => true
    • Objects.useful? # => trueConsistent modeling across the stack.
    • Objects.useful? # => trueHelpful in representing the real world.
    • Objects.useful? # => true Fun and expressive.
    • Thanks!@zombidev