Erlang, The Road Movie           Lessons learned in Erlang Land                                @drkrab                    ...
About Me    ■ Language Geek Emacs/TeX Hacker,      GCC: Objective C, NeXT, Compiled Java,      Ph.D. from Århus [language ...
’90s Object Revolution3
’90s Object Revolution    Increased    Complexity4
’90s Object Revolution       Increased       Complexity    Program Structure4
’90s Object Revolution       Increased       Complexity         Component Reuse    Program Structure4
’90s Object Revolution       Increased       Complexity              Domain Modeling         Component Reuse    Program St...
Languages                              C#   Ruby              C++         Smalltalk     Java    Simula         Objective-C5
Thinking Tools              Patterns               DDD               UML         OOA&D                                C#  ...
American               Scandinavian      School                   School       Increased       Complexity              Dom...
American               Scandinavian      School                   School       Increased                Conceptual       C...
American               Scandinavian      School                   School      Economics      Increased                 Con...
American                 Scandinavian      School                     School                        Internet       Increas...
Internet       Increased       Complexity              Domain Modeling         Component Reuse    Program Structure9
More Complexity10
More Complexity     Infrastructure made of Software10
More Complexity     Infrastructure made of Software11
More Complexity     Infrastructure made of Software12
More Complexity        Infrastructure made of Software     Fault Tolerance, Availability, QoS12
More Complexity        Infrastructure made of Software          Integration, Coordination     Fault Tolerance, Availabilit...
More Complexity        Infrastructure made of Software                Cloud, Multi-Core          Integration, Coordination...
More Complexity     We  ’re struggling to                               n dle these with an                            haS...
Time for a new         revolution?                Cloud, Multi-Core          Integration, Coordination     Fault Tolerance...
What’s a     Revolution?     Thomas Kuhn     The Structure of Scientific Revolutions14
paradigm paradigm15
paradigm paradigm15
paradigm paradigm normal science15
paradigm           observe           anomalies paradigm normal science15
paradigm           observe           anomalies paradigm       CRISIS normal science15
paradigm           observe           anomalies paradigm       CRISIS normal          revolutionary science         science15
paradigm           observe           anomalies             normal                                 science paradigm       C...
What is the                                      right paradigm to                                       cope with these? ...
What is the                                      right paradigm to                                       cope with these? ...
Johnso   n’s blog             Ralph             Next J  ava”             What is the             “Erl  ang, the           ...
Objects               Actors17
Actors     Objects17
Actors     Objects       American        School       Performance       Engineering17
Actors     Objects       American      Scandinavian        School          School       Performance    Conceptual       En...
Actors               anomalies     Objects       American            Scandinavian        School                School     ...
Actors               Quest in this talk:                anomalies     Objects         If Actor-Prog ramming               ...
18
Making reliable     distributed control systems     in the presence of errors19
Making reliable     distributed control systems     in the presence of errors19
Making reliable     distributed control systems     in the presence of errors      ■ The “secret weapon” for        Ericss...
Making reliable     distributed control systems     in the presence of errors      ■ The “secret weapon” for        Ericss...
Erlang/OTP       Open Telecommunications Platform                         ■ Embedded                           Distributed...
How to Learn Erlang21
How to Learn Erlang           diss ect a frog,     Don’t          Build  One!                    Nicolas Negropont        ...
Your Erlang Program            Platform Framework     BEAM       BEAM Emulator            BIFs             Your favorite O...
Your Erlang Program            Platform Framework     BEAM       BEAM Emulator            BIFs             Your favorite O...
Your Erlang Program            Platform Framework     BEAM            ERJANG              BIFs     JVM            Java Vir...
Anomalies in     the object-oriented          world view24
Figure 2-1                                      Interface and implementation                                   interface  ...
Figure 3-1                  An object     Encapsulation                             m et h o d                            ...
and a data structure that serves     Figure 3-1          An object          fields of its data structure are it           ...
and a data structure that serves     Figure 3-1          An object          fields of its data structure are it           ...
and a data structure that serves     Figure 3-1          An object          fields of its data structure are it           ...
and a data structure that serves     Figure 3-1          An object          fields of its data structure are it           ...
and a data structure that serves     Figure 3-1          An object          fields of its data structure are it           ...
and a data structure that serves     Figure 3-1          An object          fields of its data structure are it           ...
and a data structure that serves those functions. The functions are known as the object’s methods, a                      ...
and a data structure that serves those functions. The functions are known as the object’s methods, a                      ...
and a data structure that serves those functions. The functions are known as the object’s methods, a                      ...
Active Object +     State Machine Figure 3-1                  An object          mailbox                                 m...
Active Object +     State Machine Figure 3-1                  An object          mailbox                                 m...
Active Object +     State Machine Figure 3-1                    An object            mailbox                              ...
Active Object +     State Machine Figure 3-1                    An object            mailbox                              ...
box      empty      full(X)31
box                  empty     {‘put’,X}                  full(X)31
box                  empty     {‘put’,X}              {‘take’,From} /                            send(From, X)            ...
box() ➞ empty().     empty() ➞                        box      receive       {‘put’, X} ➞          full(X)      end.      ...
box() ➞ empty().     empty() ➞                        box      receive       {‘put’, X} ➞          full(X)      end.      ...
box() ➞ empty().     empty() ➞                             box      receive       {‘put’, X} ➞          full(X)      end. ...
box() ➞ empty().     empty() ➞                             box      receive       {‘put’, X} ➞          full(X)      end. ...
box() ➞ empty().     empty() ➞      receive       {‘put’, X} ➞           full(X)      end.     full(X) ➞      receive     ...
box() ➞ empty().          Box = spawn(fun box/0),     empty() ➞      receive       {‘put’, X} ➞           full(X)      end...
box() ➞ empty().          Box = spawn(fun box/0),     empty() ➞                 Box ! {‘put’, 27},      receive       {‘pu...
box() ➞ empty().          Box = spawn(fun box/0),     empty() ➞                 Box ! {‘put’, 27},      receive       {‘pu...
Interface     Objects                   Fixed API                   Protocol     Actors      API changes               wit...
ma ly               A no   Interface     Objects                      Fixed API                      Protocol     Actors  ...
Pull vs. Push37
Pull vs. Push37
Pull vs. Push37
Pull vs. Push37
Pull vs. Push37
Pull vs. Push37
But isn’t this expensive?38
But isn’t this expensive?      ... heard in the ‘90s       Use Objects!38
But isn’t this expensive?      ... heard in the ‘90s                        100.000’s of objects,       Use Objects!      ...
But isn’t this expensive?      ... heard yesterday      Use Actors!38
But isn’t this expensive?      ... heard yesterday                       100.000’s of processes,      Use Actors!         ...
fields of its data structu                               hide them from the rest     Effect Containment 3-1               ...
From C++ to Java      Garbage Collection     From Java to Erlang   State Containment40
Activity Composition          The Object Model                                                     The Object Model       ...
Activity Composition          The Object Model                                                     The Object Model       ...
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Erlang, The Road Movie [GOTO:CPH 2011 Keynote]
Upcoming SlideShare
Loading in …5
×

Erlang, The Road Movie [GOTO:CPH 2011 Keynote]

5,838 views
5,705 views

Published on

In November 2009 I set out on a journey to learn Erlang. And not just learn it: I wanted to immerse myself in it, get under it's skin, feel it, get to think like Erlang. I took it for a test drive, and ended up spending 18 months in Erlang's company.

This is the story of my trip. Not so much a talk about Erlang itself, but about what I realized on the way about where things are going. The systems that we build are getting increasingly integrated, distributed, and fragile. And becoming so at a disturbing rate when I think about it.

Viewing the world from behind the steering wheel of this old beauty, I'll take you on a tour of some of the significant issues we're dealing with in today's software systems: cloud, multi-core, integration, high availability, and living with the fact that our software isn't perfect.

Published in: Technology, News & Politics
0 Comments
16 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
5,838
On SlideShare
0
From Embeds
0
Number of Embeds
1,022
Actions
Shares
0
Downloads
0
Comments
0
Likes
16
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Erlang, The Road Movie [GOTO:CPH 2011 Keynote]

    1. 1. Erlang, The Road Movie Lessons learned in Erlang Land @drkrab Kresten Krab Thorup CTO, Trifork1
    2. 2. About Me ■ Language Geek Emacs/TeX Hacker, GCC: Objective C, NeXT, Compiled Java, Ph.D. from Århus [language design] ■ Developer J2EE AppServer, CORBA/RMI, XA-TM, Java Firefighter ■ Trifork CTO Technology Adoption Conference Editor, GOTO/QCon2
    3. 3. ’90s Object Revolution3
    4. 4. ’90s Object Revolution Increased Complexity4
    5. 5. ’90s Object Revolution Increased Complexity Program Structure4
    6. 6. ’90s Object Revolution Increased Complexity Component Reuse Program Structure4
    7. 7. ’90s Object Revolution Increased Complexity Domain Modeling Component Reuse Program Structure4
    8. 8. Languages C# Ruby C++ Smalltalk Java Simula Objective-C5
    9. 9. Thinking Tools Patterns DDD UML OOA&D C# Ruby C++ Smalltalk Java Simula Objective-C6
    10. 10. American Scandinavian School School Increased Complexity Domain Modeling Component Reuse Program Structure7
    11. 11. American Scandinavian School School Increased Conceptual Complexity Modeling Pa rticipatory Design Domain Modeling Component Reuse Program Structure7
    12. 12. American Scandinavian School School Economics Increased Conceptual Reuse Complexity Modeling Engineering Pa rticipatory Design Domain Modeling Component Reuse Program Structure7
    13. 13. American Scandinavian School School Internet Increased Complexity Domain Modeling Component Reuse Program Structure8
    14. 14. Internet Increased Complexity Domain Modeling Component Reuse Program Structure9
    15. 15. More Complexity10
    16. 16. More Complexity Infrastructure made of Software10
    17. 17. More Complexity Infrastructure made of Software11
    18. 18. More Complexity Infrastructure made of Software12
    19. 19. More Complexity Infrastructure made of Software Fault Tolerance, Availability, QoS12
    20. 20. More Complexity Infrastructure made of Software Integration, Coordination Fault Tolerance, Availability, QoS12
    21. 21. More Complexity Infrastructure made of Software Cloud, Multi-Core Integration, Coordination Fault Tolerance, Availability, QoS12
    22. 22. More Complexity We ’re struggling to n dle these with an haSoftware Infrastructure made of object mindset! Cloud, Multi-Core Integration, Coordination Fault Tolerance, Availability, QoS12
    23. 23. Time for a new revolution? Cloud, Multi-Core Integration, Coordination Fault Tolerance, Availability, QoS13
    24. 24. What’s a Revolution? Thomas Kuhn The Structure of Scientific Revolutions14
    25. 25. paradigm paradigm15
    26. 26. paradigm paradigm15
    27. 27. paradigm paradigm normal science15
    28. 28. paradigm observe anomalies paradigm normal science15
    29. 29. paradigm observe anomalies paradigm CRISIS normal science15
    30. 30. paradigm observe anomalies paradigm CRISIS normal revolutionary science science15
    31. 31. paradigm observe anomalies normal science paradigm CRISIS normal revolutionary science science15
    32. 32. What is the right paradigm to cope with these? Cloud, Multi-Core Integration, Coordination Fault Tolerance, Availability, QoS16
    33. 33. What is the right paradigm to cope with these? Cloud, Multi-Core Integration, Coordination Fault Tolerance, Availability, QoS Parallel Compilers Erlang, Actor Models Functional, Data-Parallel16
    34. 34. Johnso n’s blog Ralph Next J ava” What is the “Erl ang, the right paradigm to a very with these? g to be cope rlang is goin Its main ... E uage ... imp orta nt lang erfectly e is tha t it is p a Cloud, Multi-Core core, web dvantag for the multi- suite d Integration, Coordinationt, i t is the future . In fac services -QoSd ck soli NLY ma ture, ro Fault Tolerance, Availability, ble for O ge that is suita lang ua Parallel stems able sy Compilers hly scal ing hig Erlang, Actor iModels h nes. writ ore mac run on multic to Functional, Data-Parallel16
    35. 35. Objects Actors17
    36. 36. Actors Objects17
    37. 37. Actors Objects American School Performance Engineering17
    38. 38. Actors Objects American Scandinavian School School Performance Conceptual Engineering Modeling17
    39. 39. Actors anomalies Objects American Scandinavian School School Performance Conceptual Engineering Modeling17
    40. 40. Actors Quest in this talk: anomalies Objects If Actor-Prog ramming Paradigm, is the new Scandinavian American School re the What a anomalies School ance uld see Coow? tual Perform sho we n ncep Engineering Modeling17
    41. 41. 18
    42. 42. Making reliable distributed control systems in the presence of errors19
    43. 43. Making reliable distributed control systems in the presence of errors19
    44. 44. Making reliable distributed control systems in the presence of errors ■ The “secret weapon” for Ericsson’s market leading, real-time telephony systems.19
    45. 45. Making reliable distributed control systems in the presence of errors ■ The “secret weapon” for Ericsson’s market leading, real-time telephony systems. ■ 20+ years of experience to learn from.19
    46. 46. Erlang/OTP Open Telecommunications Platform ■ Embedded Distributed Systems ■ High Availability ■ In-Production Upgrades20
    47. 47. How to Learn Erlang21
    48. 48. How to Learn Erlang diss ect a frog, Don’t Build One! Nicolas Negropont e21
    49. 49. Your Erlang Program Platform Framework BEAM BEAM Emulator BIFs Your favorite OS22
    50. 50. Your Erlang Program Platform Framework BEAM BEAM Emulator BIFs Your favorite OS22
    51. 51. Your Erlang Program Platform Framework BEAM ERJANG BIFs JVM Java Virtual Machine Your favorite OS23
    52. 52. Anomalies in the object-oriented world view24
    53. 53. Figure 2-1 Interface and implementation interface implementation 11 10 9 8 7 625 Looking at such a unit from the inside, as the implem Graphics from Object-Oriented Programming with Objective C, Apple, 2011
    54. 54. Figure 3-1 An object Encapsulation m et h o d me et h o d data thod m m et h o d26
    55. 55. and a data structure that serves Figure 3-1 An object fields of its data structure are it hide them from the rest of the The insight of object-oriented programming is to combine st m et h o da high-level unit, an object, and to give it language su data—in Figure 3-1 An object me and a data structure that serves those functions. The function m et h o d data thod fields of its data structure are its instanceovariables. The met hide them from the rest of the program, m et has Figure 3-1 illustrat d me m et h o d m et h o d data thod Figure 3-1 An object m et h o d m et h o d If you’ve ever tackled any kind of difficult programming problem groups of functions that work on a particular kind of data—implic me m et h o d Object-oriented programming makes these function groups expl data thod group, rather than its components.If you’ve ever tackled any kind The only way to an object’s dat m et h o d groups of functions that work o Object-oriented programming By combining both state and behavior in a single unit, an object b really is greater than the sum of itsgroup, rather thanis a componen parts. An object its kind of se over a specific functional area. It can play a full-fledged modular If you’ve ever tackled any kind By difficult programmingand be of combining both state prob really is greater than the sum o groups of functions that work on a particular kind of data—im27 Terminology: Object-oriented terminology varies from language
    56. 56. and a data structure that serves Figure 3-1 An object fields of its data structure are it hide them from the rest of the The insight of object-oriented programming is to combine st m et h o da high-level unit, an object, and to give it language su data—in Figure 3-1 An object me and a data structure that serves those functions. The function m et h o d data thod fields of its data structure are its instanceovariables. The met hide them from the rest of the program, m et has Figure 3-1 illustrat d me m et h o d m et h o d data thod Figure 3-1 An object m et h o d m et h o d If you’ve ever tackled any kind of difficult programming problem groups of functions that work on a particular kind of data—implic me m et h o d Object-oriented programming makes these function groups expl data thod group, rather than its components.If you’ve ever tackled any kind The only way to an object’s dat m et h o d groups of functions that work o Object-oriented programming By combining both state and behavior in a single unit, an object b really is greater than the sum of itsgroup, rather thanis a componen parts. An object its kind of se over a specific functional area. It can play a full-fledged modular If you’ve ever tackled any kind By difficult programmingand be of combining both state prob really is greater than the sum o groups of functions that work on a particular kind of data—im27 Terminology: Object-oriented terminology varies from language
    57. 57. and a data structure that serves Figure 3-1 An object fields of its data structure are it hide them from the rest of the The insight of object-oriented programming is to combine st m et h o da high-level unit, an object, and to give it language su data—in Figure 3-1 An object me and a data structure that serves those functions. The function m et h o d data thod fields of its data structure are its instanceovariables. The met hide them from the rest of the program, m et has Figure 3-1 illustrat d me m et h o d m et h o d data thod Figure 3-1 An object m et h o d m et h o d If you’ve ever tackled any kind of difficult programming problem groups of functions that work on a particular kind of data—implic me m et h o d Object-oriented programming makes these function groups expl data thod group, rather than its components.If you’ve ever tackled any kind The only way to an object’s dat m et h o d groups of functions that work o Object-oriented programming By combining both state and behavior in a single unit, an object b really is greater than the sum of itsgroup, rather thanis a componen parts. An object its kind of se over a specific functional area. It can play a full-fledged modular If you’ve ever tackled any kind By difficult programmingand be of combining both state prob really is greater than the sum o groups of functions that work on a particular kind of data—im27 Terminology: Object-oriented terminology varies from language
    58. 58. and a data structure that serves Figure 3-1 An object fields of its data structure are it hide them from the rest of the The insight of object-oriented programming is to combine st m et h o da high-level unit, an object, and to give it language su data—in Figure 3-1 An object me and a data structure that serves those functions. The function m et h o d data thod fields of its data structure are its instanceovariables. The met hide them from the rest of the program, m et has Figure 3-1 illustrat d me m et h o d m et h o d data thod Figure 3-1 An object m et h o d m et h o d If you’ve ever tackled any kind of difficult programming problem groups of functions that work on a particular kind of data—implic me m et h o d Object-oriented programming makes these function groups expl data thod group, rather than its components.If you’ve ever tackled any kind The only way to an object’s dat m et h o d groups of functions that work o Object-oriented programming By combining both state and behavior in a single unit, an object b really is greater than the sum of itsgroup, rather thanis a componen parts. An object its kind of se over a specific functional area. It can play a full-fledged modular If you’ve ever tackled any kind By difficult programmingand be of combining both state prob really is greater than the sum o groups of functions that work on a particular kind of data—im27 Terminology: Object-oriented terminology varies from language
    59. 59. and a data structure that serves Figure 3-1 An object fields of its data structure are it hide them from the rest of the The insight of object-oriented programming is to combine st m et h o da high-level unit, an object, and to give it language su data—in Figure 3-1 An object me and a data structure that serves those functions. The function m et h o d data thod fields of its data structure are its instanceovariables. The met hide them from the rest of the program, m et has Figure 3-1 illustrat d me m et h o d m et h o d data thod Figure 3-1 An object m et h o d m et h o d If you’ve ever tackled any kind of difficult programming problem groups of functions that work on a particular kind of data—implic me m et h o d Object-oriented programming makes these function groups expl data thod group, rather than its components.If you’ve ever tackled any kind The only way to an object’s dat m et h o d groups of functions that work o Object-oriented programming By combining both state and behavior in a single unit, an object b really is greater than the sum of itsgroup, rather thanis a componen parts. An object its kind of se over a specific functional area. It can play a full-fledged modular If you’ve ever tackled any kind By difficult programmingand be of combining both state prob really is greater than the sum o groups of functions that work on a particular kind of data—im27 Terminology: Object-oriented terminology varies from language
    60. 60. and a data structure that serves Figure 3-1 An object fields of its data structure are it hide them from the rest of the The insight of object-oriented programming is to combine st m et h o da high-level unit, an object, and to give it language su data—in Figure 3-1 An object ma ly no me and a data structure that serves those functions. The function m et h o d data A thod fields of its data structure are its instanceovariables. The met hide them from the rest of the program, m et has Figure 3-1 illustrat d me m et h o d m et h o d data thod Figure 3-1 An object m et h o d m et h o d If you’ve ever tackled any kind of difficult programming problem groups of functions that work on a particular kind of data—implic me m et h o d Object-oriented programming makes these function groups expl data thod group, rather than its components.If you’ve ever tackled any kind The only way to an object’s dat m et h o d groups of functions that work o Object-oriented programming By combining both state and behavior in a single unit, an object b really is greater than the sum of itsgroup, rather thanis a componen parts. An object its kind of se over a specific functional area. It can play a full-fledged modular If you’ve ever tackled any kind By difficult programmingand be of combining both state prob really is greater than the sum o groups of functions that work on a particular kind of data—im27 Terminology: Object-oriented terminology varies from language
    61. 61. and a data structure that serves those functions. The functions are known as the object’s methods, a fields of its data structure are its instance variables. The methods wrap around the instance variable hide them from the rest of the program, as Figure 3-1 illustrates. The insight of object-oriented programming is to 3-1 Figure combineAn object behavior—data The insight of object-oriented programming is to combine state and and operations on CHAPTER a high-level unit, an object, and to give it language support. An object is a group of related functions data—in 3 data—in a high-level unit, an object, and to give it languag et h o d and a data structure that serves those functions.m functions are known as the object’s methods, and the serves those functions. The funct The and a data structure that fields of its data structure are its instance variables. The methods wrap around the instance variables and fields of its data structure are its instance variables. The m me m et h o d hide them from the rest of the program, as Figuredata illustrates. 3-1 hide them from the rest of the program, as Figure 3-1 illus thod Figure 3-1 An object m et h o d Figure 3-1 An object The Object Model m et h o d CHAPTER 3 m et h o d me me If you’ve ever tackled any kind of difficult programming problem, it’s likely that your design has inclu m et h o d m et h o d data groups of functions that work on a particular kind data thod thod of data—implicit “objects” without the language su Object-oriented programming makes these function groups explicit and permits you to think in terms m et h o d m et h o d group, rather than its components. The only way to an object’s data, the only interface, is through its me The insight of object-oriented programming is to combine state and behavior—data single unit, an object becomes more than either alone; the By combining both state and behavior in a and operations on The Object Model data—in a high-level unit, an object, and toreallyit language support.sumobjectparts. An object is a kind of self-sufficient “subprogram” with juris give is greater than the An of its is a group of related functions If you’ve ever tackled any kind of difficult programming problem, known that your design has included and a data structure that serves those functions. The functions areit’s likelyas the object’s methods,tackled any kind of difficult programming pr If you’ve ever and the over a specific functional area. It can play a full-fledged modular role within a larger program design groups its data structure are on a particular kind of The methods “objects” without groups variables and fields ofof functions that work its instance variables. data—implicitwrap around the instanceof functions that work on a particular kind of data— the language support. Object-oriented programming program, as function groups explicit and permits you to think in terms programming makes these function group hide them from the rest of the makes these Figure 3-1 illustrates. Object-oriented of the Terminology: Object-oriented terminology variesratherlanguage to language.The only way to an objec group, from than its components. For example, in C++, m group, rather than its components. The only way to an object’s data, the only interface, is through its methods. are called member functions and instance variables are known as data members. This document uses Figure 3-1 An object By combining both state and behavior in a terminology ofobject becomes more than basis in Smalltalk. state and behavior in a single unit, an o single unit, an Objective-C, which has its either alone; the whole By combining both The insighta kind of self-sufficient “subprogram” iscombinethan the sum of its parts. An object is a kin really is greater than the sum of its parts. An object is of object-oriented programming is to greater state and behavior—data and operations really with jurisdiction m et h o d functional area. It can play a full-fledged modular rolean object, and toover a specific functional area. It can play a full-fledged fun over a specific data—in a high-level unit, within a larger program design. support. An object is a group of related mo give it language For example, if you were to write a program that The functions are known as the object’s methods, a and a data structure that serves those functions. modeled home water usage, you might invent obje me m et h o d data fields of its data structure are its instance variables. The methods wrap around Faucet object that represent the various components of the water-delivery system. One might be a the instance variable thod Terminology: Object-oriented terminology varies from language and stopprogram, ofTerminology:methods hide methods to start to language. flow as water, set the rate of have them from the rest of the the For example, in3-1 illustrates.flow, return the amount of water con Figure C++, Object-oriented terminology varies from lan are called member functions and instance variables are known as so on. To do this work, acalled member functions and instance variables to keep m et h o d in a given period, and data members. This document uses the would need instance variables are kno are Faucet object terminology of Objective-C, which has its basis in Smalltalk. is open or shut, how much water is being used, andwhich has its basis in Smalltal of whether the tap object terminology of Objective-C, where the water is coming fr Figure 3-1 An Clearly, a programmatic Faucet object can be smarter than a real one (it’s analogous to a mechanical For example, if you were to write a program thatm et h o d problem,water usage, you mightexample, if you to If you’ve ever tackled any kind of difficult programming home it’s likely that attached). invent includedwere to like anyprogramcomponent, ex modeled For objects write a that modeled with lots of gauges and instruments your design hasBut even a real faucet, system represent functions that work on a particular kind of data—implicit “objects”be a Faucet language support. groups of the various components of the water-delivery system. One might without represent theyou need programming the water-delivery th the object that wouldcomponents of units, like objects, sy various me m et h o d both state and behavior. To effectively model a system, have methods toprogramming makes thesewater, data rate of flow, return the amountthink in terms of theand stop the flow of water, set the ra Object-oriented start and stop the flow ofcombine state and behavior. permits you to of methods to start set the have water consumed thod function groups explicit and in a given period, and so on. To doThe only wayFaucet object would need instance variables toperiod, and so on. To do this work, a Faucet ob group, rather than its components. this work, a to an object’s data, the only interface, is through its methods. in a given keep track of whether the tap is open or shut, how much water is being used,network of interconnected objects that open or shut, how much water part o A program consists of a and where the water is coming from.is call upon each other to solve a is bei m et h o d of whether the tap By combining both state and behavior in a puzzle unit, an objectin Figure 3-2 (page 16)). Each object has a specific role to play in the overall des single (as illustrated becomes more than either alone; the whole Clearly, a programmatic Faucet its parts. An object is athan a real one (it’s analogous Clearly, a programmatic Faucet object can be smarter tha really is greater than the sum of object can be smarter kind of self-sufficient “subprogram” with jurisdiction to a mechanical faucet the program and is able to communicate with other objects. Objects communicate through messages with a specific functional area. It can attached). But evenmodular role within a larger program design. over lots of gauges and instruments play a full-fledged to perform methods. systemwith lots of gauges and instruments attached). But even a a real faucet, like any component, exhibits are requests both state and behavior. To effectively model a system, you need programming units, like objects, that also it’s likely that your design has inclu If you’ve ever tackled any kind of difficult programming problem, To effectively model a system, yo both state and behavior. combine state and behavior. groups of functions that work on a particular kind ofstate and behavior. combine data—implicit “objects” without the language su Terminology: Object-oriented terminology varies from language to language. For example, in C++, methods and permits you to think in terms Object-oriented programming makes these function groups explicit28 are called member functions and instance variables are known ascall upon each otherdocument part of the a network interface, is through its me group, rather than its data members. This A solvean object’s of A program consists of a network of interconnected objects thatcomponents. The onlytoprogramuses thedata, the only of interconnected object way to a consists
    62. 62. and a data structure that serves those functions. The functions are known as the object’s methods, a fields of its data structure are its instance variables. The methods wrap around the instance variable hide them from the rest of the program, as Figure 3-1 illustrates. The insight of object-oriented programming is to 3-1 Figure combineAn object behavior—data The insight of object-oriented programming is to combine state and and operations on CHAPTER a high-level unit, an object, and to give it language support. An object is a group of related functions data—in 3 data—in a high-level unit, an object, and to give it languag et h o d and a data structure that serves those functions.m functions are known as the object’s methods, and the serves those functions. The funct The and a data structure that fields of its data structure are its instance variables. The methods wrap around the instance variables and fields of its data structure are its instance variables. The m me m et h o d hide them from the rest of the program, as Figuredata illustrates. 3-1 hide them from the rest of the program, as Figure 3-1 illus thod Figure 3-1 An object m et h o d Figure 3-1 An object The Object Model m et h o d CHAPTER 3 m et h o d me me If you’ve ever tackled any kind of difficult programming problem, it’s likely that your design has inclu m et h o d m et h o d data groups of functions that work on a particular kind data thod thod of data—implicit “objects” without the language su Object-oriented programming makes these function groups explicit and permits you to think in terms m et h o d m et h o d group, rather than its components. The only way to an object’s data, the only interface, is through its me The insight of object-oriented programming is to combine state and behavior—data single unit, an object becomes more than either alone; the By combining both state and behavior in a and operations on The Object Model data—in a high-level unit, an object, and toreallyit language support.sumobjectparts. An object is a kind of self-sufficient “subprogram” with juris give is greater than the An of its is a group of related functions If you’ve ever tackled any kind of difficult programming problem, known that your design has included and a data structure that serves those functions. The functions areit’s likelyas the object’s methods,tackled any kind of difficult programming pr If you’ve ever and the over a specific functional area. It can play a full-fledged modular role within a larger program design groups its data structure are on a particular kind of The methods “objects” without groups variables and fields ofof functions that work its instance variables. data—implicitwrap around the instanceof functions that work on a particular kind of data— the language support. Object-oriented programming program, as function groups explicit and permits you to think in terms programming makes these function group hide them from the rest of the makes these Figure 3-1 illustrates. Object-oriented of the Terminology: Object-oriented terminology variesratherlanguage to language.The only way to an objec group, from than its components. For example, in C++, m group, rather than its components. The only way to an object’s data, the only interface, is through its methods. are called member functions and instance variables are known as data members. This document uses Figure 3-1 An object By combining both state and behavior in a terminology ofobject becomes more than basis in Smalltalk. state and behavior in a single unit, an o single unit, an Objective-C, which has its either alone; the whole By combining both The insighta kind of self-sufficient “subprogram” iscombinethan the sum of its parts. An object is a kin really is greater than the sum of its parts. An object is of object-oriented programming is to greater state and behavior—data and operations really with jurisdiction m et h o d functional area. It can play a full-fledged modular rolean object, and toover a specific functional area. It can play a full-fledged fun over a specific data—in a high-level unit, within a larger program design. support. An object is a group of related mo give it language For example, if you were to write a program that The functions are known as the object’s methods, a and a data structure that serves those functions. modeled home water usage, you might invent obje me m et h o d data fields of its data structure are its instance variables. The methods wrap around Faucet object that represent the various components of the water-delivery system. One might be a the instance variable thod Terminology: Object-oriented terminology varies from language and stopprogram, ofTerminology:methods hide methods to start to language. flow as water, set the rate of have them from the rest of the the For example, in3-1 illustrates.flow, return the amount of water con Figure C++, Object-oriented terminology varies from lan are called member functions and instance variables are known as so on. To do this work, acalled member functions and instance variables to keep m et h o d in a given period, and data members. This document uses the would need instance variables are kno are Faucet object terminology of Objective-C, which has its basis in Smalltalk. is open or shut, how much water is being used, andwhich has its basis in Smalltal of whether the tap object terminology of Objective-C, where the water is coming fr Figure 3-1 An Clearly, a programmatic Faucet object can be smarter than a real one (it’s analogous to a mechanical For example, if you were to write a program thatm et h o d problem,water usage, you mightexample, if you to If you’ve ever tackled any kind of difficult programming home it’s likely that attached). invent includedwere to like anyprogramcomponent, ex modeled For objects write a that modeled with lots of gauges and instruments your design hasBut even a real faucet, system represent functions that work on a particular kind of data—implicit “objects”be a Faucet language support. groups of the various components of the water-delivery system. One might without represent theyou need programming the water-delivery th the object that wouldcomponents of units, like objects, sy various me m et h o d both state and behavior. To effectively model a system, have methods toprogramming makes thesewater, data rate of flow, return the amountthink in terms of theand stop the flow of water, set the ra Object-oriented start and stop the flow ofcombine state and behavior. permits you to of methods to start set the have water consumed thod function groups explicit and in a given period, and so on. To doThe only wayFaucet object would need instance variables toperiod, and so on. To do this work, a Faucet ob group, rather than its components. this work, a to an object’s data, the only interface, is through its methods. in a given keep track of whether the tap is open or shut, how much water is being used,network of interconnected objects that open or shut, how much water part o A program consists of a and where the water is coming from.is call upon each other to solve a is bei m et h o d of whether the tap By combining both state and behavior in a puzzle unit, an objectin Figure 3-2 (page 16)). Each object has a specific role to play in the overall des single (as illustrated becomes more than either alone; the whole Clearly, a programmatic Faucet its parts. An object is athan a real one (it’s analogous Clearly, a programmatic Faucet object can be smarter tha really is greater than the sum of object can be smarter kind of self-sufficient “subprogram” with jurisdiction to a mechanical faucet the program and is able to communicate with other objects. Objects communicate through messages with a specific functional area. It can attached). But evenmodular role within a larger program design. over lots of gauges and instruments play a full-fledged to perform methods. systemwith lots of gauges and instruments attached). But even a a real faucet, like any component, exhibits are requests both state and behavior. To effectively model a system, you need programming units, like objects, that also it’s likely that your design has inclu If you’ve ever tackled any kind of difficult programming problem, To effectively model a system, yo both state and behavior. combine state and behavior. groups of functions that work on a particular kind ofstate and behavior. combine data—implicit “objects” without the language su Terminology: Object-oriented terminology varies from language to language. For example, in C++, methods and permits you to think in terms Object-oriented programming makes these function groups explicit28 are called member functions and instance variables are known ascall upon each otherdocument part of the a network interface, is through its me group, rather than its data members. This A solvean object’s of A program consists of a network of interconnected objects thatcomponents. The onlytoprogramuses thedata, the only of interconnected object way to a consists
    63. 63. and a data structure that serves those functions. The functions are known as the object’s methods, a fields of its data structure are its instance variables. The methods wrap around the instance variable hide them from the rest of the program, as Figure 3-1 illustrates. The insight of object-oriented programming is to 3-1 Figure combineAn object behavior—data The insight of object-oriented programming is to combine state and and operations on CHAPTER 3 CHAPTER a high-level unit, an object, and to give it language support. An object is a group of related functions data—in 3 data—in a high-level unit, an object, and to give it languag et h o d and a data structure that serves those functions.m functions are known as the object’s methods, and the serves those functions. The funct The and a data structure that fields of its data structure are its instance variables. The methods wrap around the instance variables and fields of its data structure are its instance variables. The m me m et h o d hide them from the rest of the program, as Figuredata illustrates. 3-1 hide them from the rest of the program, as Figure 3-1 illus thod Figure 3-1 An object Figure 3-1 An object The Object Model m et h o d The Object Model m et h o d CHAPTER 3 m et h o d me me If you’ve ever tackled any kind of difficult programming problem, it’s likely that your design has inclu m et h o d m et h o d data groups of functions that work on a particular kind data thod thod of data—implicit “objects” without the language su Object-oriented programming makes these function groups explicit and permits you to think in terms m et h o d m et h o d group, rather than its components. The only way to an object’s data, the only interface, is through its me The insight of object-oriented programming is to combine The insight of object-oriented programming is to combine state and behavior—data data—in a high-level unit, an object, and to give it languag and operations on The Object Model By combining both state and behavior in a single unit, an object becomes more than either alone; the data—in a high-level unit, an object, and toreallyit language support.sumobjectparts. An object is a kind of self-sufficient “subprogram” withfunct give is greater than the An of its is a group of related functions serves those functions. The juris and a data structure that If you’ve ever tackled any kind of difficult programming problem, known that your design has included and a data structure that serves those functions. The functions areit’s likelyas the object’s methods,tackled any kind ofinstance programming pr If you’ve its data structure fields of ever and the difficult variables. The over a specific functional area. It can play a full-fledged modular roleare its a larger program designm within groups its data structure are on a particular kind of The methods “objects” without groups variables and work program, as Figure 3-1 illus fields ofof functions that work its instance variables. data—implicitwrap around the instanceof functions that of theon a particular kind of data— hidelanguage support. the them from the rest Object-oriented programming program, as function groups explicit and permits you to think in terms programming makes these function group hide them from the rest of the makes these Figure 3-1 illustrates. Object-oriented of the Terminology: Object-oriented terminology variesratherlanguage to language.The only way to an objec group, from than its components. For example, in C++, m group, rather than its components. The only way to an object’s data, the only interface, is through its methods. Figure 3-1 are called member functions and instance variables are knownobject members. This document uses An as data Figure 3-1 An object By combining both state and behavior in a terminology ofobject becomes more than basis in Smalltalk. state and behavior in a single unit, an o single unit, an Objective-C, which has its either alone; the whole By combining both The insighta kind of self-sufficient “subprogram”m combinethan the sum of its parts. An object is a kin really is greater than the sum of its parts. An object is of object-oriented programming is to et h ojurisdictionand behavior—data and operations really is greater state with d et h o d over a specific functional area. It can play a full-fledged modular rolean object, and toover a specific functional area. It can play a full-fledged fun m data—in a high-level unit, within a larger program design. support. An object is a group of related mo give it language me m et h o d For example, if you were to write a program that The functions are known as the object’s methods, a and a data structure that serves those functions. modeled home water usage, you might invent obje me m et h o d data thod data fields of its data structure are its instance variables. The methods wrap around Faucet object that represent the various components of the water-delivery system. One might be a the instance variable thod Terminology: Object-oriented terminology varies from language and stopprogram, ofTerminology:methods hide methods to start to language. flow as water, set the rate of have them from the rest of the the For example, in3-1 illustrates.flow, return the amount of water con Figure C++, Object-oriented terminology varies from lan m et h o d are called member functions and instance variables are known as so on. To do this work, acalled member functions and instance variables to keep m et h o d in a given period, and data members. This document uses the would need instance variables are kno are Faucet object terminology of Objective-C, which has its basis in Smalltalk. is open or shut, how much water is being used, andwhich has its basis in Smalltal of whether the tap object terminology of Objective-C, where the water is coming fr Figure 3-1 An Clearly, a programmatic Faucet object can be smarter than a real one (it’sof difficult programming pr analogous to a mechanical For example, if you were to write a program thatm et h o d problem,water usage, you mightexample, if you to anyto write a program that modeled modeled home it’s likely that your design has includedwere kind If you’ve ever tackled any kind of difficult programming If you’ve ever tackled For invent objects with lots of gauges and instruments attached). But even a real faucet, like any system component, ex represent functions that work on a particular kind of data—implicit “objects”be a Faucet language support. work on a particular kind of data— groups of the various components of the water-delivery system. One might without groups of functions that represent the various components of the water-delivery sy the object that would me m et h o d both state and behavior. To effectively model a system, you need programming units, like objects, th have methods toprogramming makes thesewater, data rate of flow, return the amountthink in terms of theand stop the flow of function the ra Object-oriented programming makes thesewater, set group Object-oriented start and stop the flow ofcombine state and behavior. permits you to of methods to start set the have water consumed thod function groups explicit and in a given period, and so on. To doThe only wayFaucet object would need instance variables toperiod, and so on. To doThe only wayFaucet ob group, rather than its components. this work, a to an objec group, rather than its components. this work, a to an object’s data, the only interface, is through its methods. in a given keep track of whether the tap is open or shut, how much water is being used,network of interconnected objects that open or shut, how much water part o A program consists of a and where the watercombining from.is calland behavior in a single unit, an o of whether the tap is coming is bei both state upon each other to solve a m et h o d By By combining both state and behavior in a puzzle unit, an objectin Figure 3-2 (page 16)). Each greater has a the sumrole to play in the overall des single (as illustrated becomes more than either alone; thethan specific of object whole Clearly, a programmatic Faucet its parts. An object is athan a real one (it’s analogous really is a programmatic Faucet its parts. An object is atha really is greater than the sum of object can be smarter kind of self-sufficient “subprogram” with jurisdiction Clearly, to a mechanical faucet object can be smarter kin the program and is able to communicate with other objects. Objects communicate through messages over a specific functional area. It can play a full-fledged mo with a specific functional area. It can attached). But evenmodular role within a larger program design. over lots of gauges and instruments play a full-fledged to perform methods. systemwith lots of gauges and instruments attached). But even a a real faucet, like any component, exhibits are requests both state and behavior. To effectively model a system, you need programming units, like objects, that also it’s likely that your design has inclu If you’ve ever tackled any kind of difficult programming problem, To effectively model a system, yo both state and behavior. combine state and behavior. groups of functions that work on a particular kind ofstate Object-oriented terminology varies from lan combine data—implicit “objects” without the language su Terminology: and behavior. Terminology: Object-oriented terminology varies from language to language. For example, in C++, methods and permits youvariablesin terms Object-oriented programming makes these function memberexplicit and instance to think are kno are called groups functions28 are called member functions and instance variables are known ascall upon each otherdocument part of the a network interface,basis in Smalltal data members. This A programuses Objective-C, only ofhas its is through its me group, rather than its terminology of the of A program consists of a network of interconnected objects thatcomponents. The onlyto solvean object’s data, the which interconnected object way to a consists
    64. 64. Active Object + State Machine Figure 3-1 An object mailbox m et h o d me et h o d data thod m m et h o d29
    65. 65. Active Object + State Machine Figure 3-1 An object mailbox m et h o d me et h o d data thod m m et h o d29
    66. 66. Active Object + State Machine Figure 3-1 An object mailbox m et h o d me et h o d data thod m m et h o d30
    67. 67. Active Object + State Machine Figure 3-1 An object mailbox m et h o d me et h o d data thod m m et h o d30
    68. 68. box empty full(X)31
    69. 69. box empty {‘put’,X} full(X)31
    70. 70. box empty {‘put’,X} {‘take’,From} / send(From, X) full(X)31
    71. 71. box() ➞ empty(). empty() ➞ box receive {‘put’, X} ➞ full(X) end. empty full(X) ➞ {‘put’,X} {‘take’,From} / send(From, X) receive {‘take’, From} ➞ full(X) From ! X, empty() end.32
    72. 72. box() ➞ empty(). empty() ➞ box receive {‘put’, X} ➞ full(X) end. empty full(X) ➞ {‘put’,X} {‘take’,From} / send(From, X) receive {‘take’, From} ➞ full(X) From ! X, empty() end. {‘peek’,From} / send(From,{‘ok’, X})33
    73. 73. box() ➞ empty(). empty() ➞ box receive {‘put’, X} ➞ full(X) end. empty full(X) ➞ {‘put’,X} {‘take’,From} / send(From, X) receive {‘take’, From} ➞ full(X) From ! X, empty(); {‘peek’, From} ➞ {‘peek’,From} / send(From,{‘ok’, X}) From ! {‘ok’, X}, full(X) end.34
    74. 74. box() ➞ empty(). empty() ➞ box receive {‘put’, X} ➞ full(X) end. empty full(X) ➞ {‘put’,X} {‘take’,From} / send(From, X) receive {‘take’, From} ➞ full(X) From ! X, empty(); {‘peek’, From} ➞ {‘peek’,From} / send(From,{‘ok’, X}) From ! {‘ok’, X}, full(X) end.34
    75. 75. box() ➞ empty(). empty() ➞ receive {‘put’, X} ➞ full(X) end. full(X) ➞ receive {‘take’, From} ➞ From ! X, empty(); {‘peek’, From} ➞ From ! {‘ok’, X}, full(X) end.35
    76. 76. box() ➞ empty(). Box = spawn(fun box/0), empty() ➞ receive {‘put’, X} ➞ full(X) end. full(X) ➞ receive {‘take’, From} ➞ From ! X, empty(); {‘peek’, From} ➞ From ! {‘ok’, X}, full(X) end.35
    77. 77. box() ➞ empty(). Box = spawn(fun box/0), empty() ➞ Box ! {‘put’, 27}, receive {‘put’, X} ➞ full(X) end. full(X) ➞ receive {‘take’, From} ➞ From ! X, empty(); {‘peek’, From} ➞ From ! {‘ok’, X}, full(X) end.35
    78. 78. box() ➞ empty(). Box = spawn(fun box/0), empty() ➞ Box ! {‘put’, 27}, receive {‘put’, X} ➞ Box ! {‘take’, self()}, full(X) receive end. Value ➞ print(Value) end full(X) ➞ receive {‘take’, From} ➞ From ! X, empty(); {‘peek’, From} ➞ From ! {‘ok’, X}, full(X) end.35
    79. 79. Interface Objects Fixed API Protocol Actors API changes with internal state36
    80. 80. ma ly A no Interface Objects Fixed API Protocol Actors API changes with internal state36
    81. 81. Pull vs. Push37
    82. 82. Pull vs. Push37
    83. 83. Pull vs. Push37
    84. 84. Pull vs. Push37
    85. 85. Pull vs. Push37
    86. 86. Pull vs. Push37
    87. 87. But isn’t this expensive?38
    88. 88. But isn’t this expensive? ... heard in the ‘90s Use Objects!38
    89. 89. But isn’t this expensive? ... heard in the ‘90s 100.000’s of objects, Use Objects! are you crazy?38
    90. 90. But isn’t this expensive? ... heard yesterday Use Actors!38
    91. 91. But isn’t this expensive? ... heard yesterday 100.000’s of processes, Use Actors! silly you!38
    92. 92. fields of its data structu hide them from the rest Effect Containment 3-1 Figure An obje m et h o d ■ Functional languages me et h o d disallow effects data thod ■ Many object-oriented m m et h o d styles encourage side effects. ■ Actors confine effects If you’ve ever tackled an groups of functions tha Object-oriented program39 group, rather than its co
    93. 93. From C++ to Java Garbage Collection From Java to Erlang State Containment40
    94. 94. Activity Composition The Object Model The Object Model The insight of object-oriented programming is to combine state and behavior—data and operations on The insight of object-oriented programming is to combine state and data—in a high-level unit, an object, and to give it language support. An object is a group of related functions give it language support. data—in a high-level unit, an object, and to and a data the object’s methods, and the and a data structure that serves those functions. The functions are known asstructure that serves those functions. The functions are k fields of its data structure are its instance variables. The methods wrap around the instance variables and variables. The methods w fields of its data structure are its instance hide them from the rest of the program, as Figure 3-1 illustrates. hide them from the rest of the program, as Figure 3-1 illustrates. Figure 3-1 An object Figure 3-1 An object m et h o d me spawn m et h o d me m et h o d m et h o d data data thod thod m et h o d m et h o d If you’ve ever tackled any kind of difficult programming problem,If you’ve ever tackled any kind included programming problem, it’ it’s likely that your design has of difficult groups of functions that work on a particular kind of data—implicit “objects” without the language a particular kind of data—implicit “ groups of functions that work on support. Object-oriented programming makes these function groups explicit and permits you to think in terms ofthese function groups explicit Object-oriented programming makes the group, rather than its components. The only way to an object’s data, the only interface, iscomponents. The only way to an object’s data, th group, rather than its through its methods. By combining both state and behavior in a single unit, an object becomes more than eitherand behavior in a single unit, an object bec By combining both state alone; the whole really is greater than the sum of its parts. An object is a kind of self-sufficient “subprogram”sum of its parts. An object is a kind of self-s really is greater than the with jurisdiction over a specific functional area. It can play a full-fledged modular role within a larger program design. play a full-fledged modular role over a specific functional area. It can Terminology: Object-oriented terminology varies from language to language. For example, in C++, methods varies from language to Terminology: Object-oriented terminology are called member functions and instance variables are known as data members. Thisfunctions and instance variables are known as da are called member document uses the terminology of Objective-C, which has its basis in Smalltalk. terminology of Objective-C, which has its basis in Smalltalk. For example, if you were to write a program that modeled home water usage, you might invent objects to that modeled home wa For example, if you were to write a program represent the various components of the water-delivery system. One mightthe a Faucet object thatof the water-delivery system. On represent be various components would have methods to start and stop the flow of water, set the rate of flow, return the amount and stop consumed water, set the rate of flow have methods to start of water the flow of41 in a given period, and so on. To do this work, a Faucet object would need instanceand so on.to keep track in a given period, variables To do this work, a Faucet object woul
    95. 95. Activity Composition The Object Model The Object Model The insight of object-oriented programming is to combine state and behavior—data and operations on The insight of object-oriented programming is to combine state and data—in a high-level unit, an object, and to give it language support. An object is a group of related functions give it language support. data—in a high-level unit, an object, and to and a data the object’s methods, and the and a data structure that serves those functions. The functions are known asstructure that serves those functions. The functions are k fields of its data structure are its instance variables. The methods wrap around the instance variables and variables. The methods w fields of its data structure are its instance hide them from the rest of the program, as Figure 3-1 illustrates. hide them from the rest of the program, as Figure 3-1 illustrates. Figure 3-1 An object Figure 3-1 An object m et h o d me link m et h o d me m et h o d m et h o d data data thod thod m et h o d m et h o d If you’ve ever tackled any kind of difficult programming problem,If you’ve ever tackled any kind included programming problem, it’ it’s likely that your design has of difficult groups of functions that work on a particular kind of data—implicit “objects” without the language a particular kind of data—implicit “ groups of functions that work on support. Object-oriented programming makes these function groups explicit and permits you to think in terms ofthese function groups explicit Object-oriented programming makes the group, rather than its components. The only way to an object’s data, the only interface, iscomponents. The only way to an object’s data, th group, rather than its through its methods. By combining both state and behavior in a single unit, an object becomes more than eitherand behavior in a single unit, an object bec By combining both state alone; the whole really is greater than the sum of its parts. An object is a kind of self-sufficient “subprogram”sum of its parts. An object is a kind of self-s really is greater than the with jurisdiction over a specific functional area. It can play a full-fledged modular role within a larger program design. play a full-fledged modular role over a specific functional area. It can Terminology: Object-oriented terminology varies from language to language. For example, in C++, methods varies from language to Terminology: Object-oriented terminology are called member functions and instance variables are known as data members. Thisfunctions and instance variables are known as da are called member document uses the terminology of Objective-C, which has its basis in Smalltalk. terminology of Objective-C, which has its basis in Smalltalk. For example, if you were to write a program that modeled home water usage, you might invent objects to that modeled home wa For example, if you were to write a program represent the various components of the water-delivery system. One mightthe a Faucet object thatof the water-delivery system. On represent be various components would have methods to start and stop the flow of water, set the rate of flow, return the amount and stop consumed water, set the rate of flow have methods to start of water the flow of42 in a given period, and so on. To do this work, a Faucet object would need instanceand so on.to keep track in a given period, variables To do this work, a Faucet object woul

    ×