SlideShare una empresa de Scribd logo
1 de 30
OO Programming - Introduction

                                                                     João Pereira
                                                                               October 2012

  OO Programming - Introduction by João Miguel Pereira is licensed under a Creative Commons Attribution-
                                                        NonCommercial-ShareAlike 3.0 Unported License.
OO Programming- Introduction


                 Refreshing OO programming concepts




OO Programming - Introduction is licensed under a Creative Commons Attribution-   2
NonCommercial-ShareAlike 3.0 Unported License.
OO Programming Concepts


    Why do I need                                                         objects   ?



OO Programming - Introduction is licensed under a Creative Commons Attribution-         3
NonCommercial-ShareAlike 3.0 Unported License.
OO Programming Concepts
   • I can easily model real world concepts.


                                                                  Car




OO Programming - Introduction is licensed under a Creative Commons Attribution-   4
NonCommercial-ShareAlike 3.0 Unported License.
OO Programming Concepts
   • I can focus on the data and behavior of
     the atoms of my system
       Focus on
     grouping the
                                                        Wheel
      state for a
                                                  Diameter
        wheel                                     Weight
                                                  Model
                                                  supporting Load

                                                  Move()
                                                  autoCalibrate()
                                                  checkPressure()                   Focus on
                                                  currentLoad()                   grouping the
                                                                                    behavior

OO Programming - Introduction is licensed under a Creative Commons Attribution-                  5
NonCommercial-ShareAlike 3.0 Unported License.
OO Programming Concepts
   • I can share objects and still have everything I
     need to use them in other systems


                     Machine A                                                    Machine B

                        Object                                                     Object
                          Object’s                                                  Object’s
                           state                               Network               state
                          Object’s                                                  Object’s
                          behavior                                                  behavior




OO Programming - Introduction is licensed under a Creative Commons Attribution-                6
NonCommercial-ShareAlike 3.0 Unported License.
OO Programming Concepts
   • I can build small, manageable, self-
     contained objects and use them as
     building blocks for bigger things

                Wheel
                                                                                  Wheel     Wheel
                   Seat
                     Belt
                                                                                    Wheel      Wheel
                          Tire




                        Objects                                                      Car OO Program

OO Programming - Introduction is licensed under a Creative Commons Attribution-                        7
NonCommercial-ShareAlike 3.0 Unported License.
OO Programming Concepts
   • I can reuse objects to build different
     systems



                Wheel
                                                                                   Wheel          Wheel
                   Seat

                                                                                           Seat




                        Objects                                                   Bike OO Program

OO Programming - Introduction is licensed under a Creative Commons Attribution-                           8
NonCommercial-ShareAlike 3.0 Unported License.
OO Programming Concepts



                                              More?


OO Programming - Introduction is licensed under a Creative Commons Attribution-   9
NonCommercial-ShareAlike 3.0 Unported License.
Programming OO



              How I design and code?



OO Programming - Introduction is licensed under a Creative Commons Attribution-   10
NonCommercial-ShareAlike 3.0 Unported License.
Programming OO
   • I don’t try to build the perfect solution
   • Tend to be creative
   • Brainstorm, sometimes with myself
   • Implement alternatives
   • Refactor my code
   • Get a bird-eye view on the whole system,
     frequently
   • Focus my effort on small parts of the system (a
     Class at a time)
OO Programming - Introduction is licensed under a Creative Commons Attribution-   11
NonCommercial-ShareAlike 3.0 Unported License.
Programming OO
   • Know the differences between the interface
     and the implementation
   • Think abstractly
   • Give users of my objects the minimal interface
     possible
   • And….
          – Know the design principles
          – Reuse knowledge (Patterns)

OO Programming - Introduction is licensed under a Creative Commons Attribution-   12
NonCommercial-ShareAlike 3.0 Unported License.
Programming OO
   • Know the differences between the interface
     and the implementation
   • Think abstractly
   • Give users of my objects the minimal interface
     possible




OO Programming - Introduction is licensed under a Creative Commons Attribution-   13
NonCommercial-ShareAlike 3.0 Unported License.
Programming OO
   Interface and Implementation                                                   interface
         Services that my objects expose to my object’s clients
           public class Computer {
              private PowerSupply powerSupply;

                public void turnOn() {
                   turnOnPowerSupply();
                }
                public void turnOff() {
                   turnOffPowerSupply();
                }

                private void turnOffPowerSupply() {
                   powerSupply.turnOff();
                }
                private void turnOnPowerSupply() {
                   powerSupply.turnOn();
                }
           }



OO Programming - Introduction is licensed under a Creative Commons Attribution-           14
NonCommercial-ShareAlike 3.0 Unported License.
Programming OO
   Interface and Implementation                                                   implementation
 Implementation is how the object realize
 the services expected by the clients
           public class Computer {
              private PowerSupply powerSupply;

                public void turnOn() {
                   turnOnPowerSupply();
                }
                public void turnOff() {
                   turnOffPowerSupply();
                }

                private void turnOffPowerSupply() {
                   powerSupply.turnOff();
                }
                private void turnOnPowerSupply() {
                   powerSupply.turnOn();
                }
           }



OO Programming - Introduction is licensed under a Creative Commons Attribution-             15
NonCommercial-ShareAlike 3.0 Unported License.
Programming OO
   Interface and Implementation

   • Object’s clients can be other objects




OO Programming - Introduction is licensed under a Creative Commons Attribution-   16
NonCommercial-ShareAlike 3.0 Unported License.
Programming OO
   Interface and Implementation

   • If an implementation change, clients don’t
     care, as long as the interface provides them the
     service they expect
          public class Computer {

               public void turnOn() {
                  PowerSupply.on();
               }
               public void turnOff() {
                  PowerSupply.off();
               }}




OO Programming - Introduction is licensed under a Creative Commons Attribution-   17
NonCommercial-ShareAlike 3.0 Unported License.
Programming OO
   • Know the differences between the interface
     and the implementation
   • Think abstractly
   • Give users of my objects the minimal interface
     possible




OO Programming - Introduction is licensed under a Creative Commons Attribution-   18
NonCommercial-ShareAlike 3.0 Unported License.
Programming OO
   Think Abstractly

   • Design interfaces as abstract as
     possible
   • Abstraction allows reuse
   • Foundation of many design
     guidelines


OO Programming - Introduction is licensed under a Creative Commons Attribution-   19
NonCommercial-ShareAlike 3.0 Unported License.
Programming OO
   Think Abstractly

   Which interface is more abstract?

  1      public class Computer {
           public void positionDiskHead(int sector) {
           }
           public void startDiskRotation() {
           }
           public Byte[] readBytes(int endSector) {
           }
           public void endDiskRotation() {
           }
         }




 2      public class Computer {
          public Byte[] readFromMedium(MediumIdentifier id, ReadInstructions instructions) {
            return null;
          }
        }

OO Programming - Introduction is licensed under a Creative Commons Attribution-          20
NonCommercial-ShareAlike 3.0 Unported License.
Programming OO
   Think Abstractly

   Which interface is more reusable?

  1      public class Computer {
           public void positionDiskHead(int sector) {
           }
           public void startDiskRotation() {
           }
           public Byte[] readBytes(int endSector) {
           }
           public void endDiskRotation() {
           }
         }




 2      public class Computer {
          public Byte[] readFromMedium(MediumIdentifier id, ReadInstructions instructions) {
            return null;
          }
        }

OO Programming - Introduction is licensed under a Creative Commons Attribution-          21
NonCommercial-ShareAlike 3.0 Unported License.
Programming OO
   • Know the differences between the interface
     and the implementation
   • Think abstractly
   • Give users of my objects the minimal
     interface possible




OO Programming - Introduction is licensed under a Creative Commons Attribution-   22
NonCommercial-ShareAlike 3.0 Unported License.
You Ain’t
   Programming OO                                                                 Gonna Need It
   Minimal interface

   • Tend to follow the YAGNI principle
   • Give clients only the strictly needed
     interfaces
   • Only add new interfaces if object’s clients
     really require it



OO Programming - Introduction is licensed under a Creative Commons Attribution-           23
NonCommercial-ShareAlike 3.0 Unported License.
Programming OO
    Minimal interface
      I give this interface to the client of my object. (In reality, I’m giving no
1     interface at all)
      public class Computer {
      }


2    The client asks, “Hey, now what? How do I turn it on?”

     I give an interface to allow the client to turn on the computer
3    public class Computer {
      public void turnOn() {}
     }

4    The client then asks, “Thanks, but… How do I turn it off?”

5    Story goes on…

OO Programming - Introduction is licensed under a Creative Commons Attribution-      24
NonCommercial-ShareAlike 3.0 Unported License.
OO Concepts
   •    Encapsulation and Data Hiding
   •    Inheritance
   •    Polymorphism
   •    Composition




OO Programming - Introduction is licensed under a Creative Commons Attribution-   25
NonCommercial-ShareAlike 3.0 Unported License.
OO Concepts
   Encapsulation and Data Hiding

   • Hide implementation details, such as state and
     behavior pertaining only the implementation
     of interface.
   • Give users only access to interfaces
        public class Computer {
           private PowerSupply powerSupply;
           public void turnOn() {                                                     What a user see
              turnOnPowerSupply();
           }
           public void turnOff() {
              turnOffPowerSupply();
           }                                                            public class Computer {
                                                                           public void turnOn() {
            private void turnOffPowerSupply() {                               turnOnPowerSupply();
               powerSupply.turnOff();                                      }
            }                                                              public void turnOff() {
            private void turnOnPowerSupply() {                                turnOffPowerSupply();
               powerSupply.turnOn();                                       }
            }                                                           }
        }


OO Programming - Introduction is licensed under a Creative Commons Attribution-                         26
NonCommercial-ShareAlike 3.0 Unported License.
OO Concepts
   Inheritance

   • Allows me to reuse code by abstracting
     common behavior and state of a set of classes




OO Programming - Introduction is licensed under a Creative Commons Attribution-   27
NonCommercial-ShareAlike 3.0 Unported License.
OO Concepts
   Polymorphism

 • I can have a have a type that assumes multiple forms
        ElectronicEquipment computer = new Computer();
        ElectronicEquipment phone = new Phone();
        computer.turnOn();
        phone.turnOn();




 • An ElectronicEquipment can assume the form of a
   Computer or a Phone
 • A user with a reference to an ElectronicEquipment
   don’t care if it’s a Computer or a Phone

OO Programming - Introduction is licensed under a Creative Commons Attribution-   28
NonCommercial-ShareAlike 3.0 Unported License.
OO Concepts
   Composition

   • Can reuse code by factor in common behavior
     and state to a separate class and use that class
     as a building block of other classes.
          – Both Printer and Computer have a PowerSupply
            and a motherborad.




OO Programming - Introduction is licensed under a Creative Commons Attribution-   29
NonCommercial-ShareAlike 3.0 Unported License.
João Pereira
                                                                                      March 2012

OO Design Principles - Introduction by João Miguel Pereira is licensed under a Creative Commons Attribution-
                                                            NonCommercial-ShareAlike 3.0 Unported License.

Más contenido relacionado

Último

Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 

Último (20)

Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 

Destacado

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Destacado (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

OO programming introduction

  • 1. OO Programming - Introduction João Pereira October 2012 OO Programming - Introduction by João Miguel Pereira is licensed under a Creative Commons Attribution- NonCommercial-ShareAlike 3.0 Unported License.
  • 2. OO Programming- Introduction Refreshing OO programming concepts OO Programming - Introduction is licensed under a Creative Commons Attribution- 2 NonCommercial-ShareAlike 3.0 Unported License.
  • 3. OO Programming Concepts Why do I need objects ? OO Programming - Introduction is licensed under a Creative Commons Attribution- 3 NonCommercial-ShareAlike 3.0 Unported License.
  • 4. OO Programming Concepts • I can easily model real world concepts. Car OO Programming - Introduction is licensed under a Creative Commons Attribution- 4 NonCommercial-ShareAlike 3.0 Unported License.
  • 5. OO Programming Concepts • I can focus on the data and behavior of the atoms of my system Focus on grouping the Wheel state for a Diameter wheel Weight Model supporting Load Move() autoCalibrate() checkPressure() Focus on currentLoad() grouping the behavior OO Programming - Introduction is licensed under a Creative Commons Attribution- 5 NonCommercial-ShareAlike 3.0 Unported License.
  • 6. OO Programming Concepts • I can share objects and still have everything I need to use them in other systems Machine A Machine B Object Object Object’s Object’s state Network state Object’s Object’s behavior behavior OO Programming - Introduction is licensed under a Creative Commons Attribution- 6 NonCommercial-ShareAlike 3.0 Unported License.
  • 7. OO Programming Concepts • I can build small, manageable, self- contained objects and use them as building blocks for bigger things Wheel Wheel Wheel Seat Belt Wheel Wheel Tire Objects Car OO Program OO Programming - Introduction is licensed under a Creative Commons Attribution- 7 NonCommercial-ShareAlike 3.0 Unported License.
  • 8. OO Programming Concepts • I can reuse objects to build different systems Wheel Wheel Wheel Seat Seat Objects Bike OO Program OO Programming - Introduction is licensed under a Creative Commons Attribution- 8 NonCommercial-ShareAlike 3.0 Unported License.
  • 9. OO Programming Concepts More? OO Programming - Introduction is licensed under a Creative Commons Attribution- 9 NonCommercial-ShareAlike 3.0 Unported License.
  • 10. Programming OO How I design and code? OO Programming - Introduction is licensed under a Creative Commons Attribution- 10 NonCommercial-ShareAlike 3.0 Unported License.
  • 11. Programming OO • I don’t try to build the perfect solution • Tend to be creative • Brainstorm, sometimes with myself • Implement alternatives • Refactor my code • Get a bird-eye view on the whole system, frequently • Focus my effort on small parts of the system (a Class at a time) OO Programming - Introduction is licensed under a Creative Commons Attribution- 11 NonCommercial-ShareAlike 3.0 Unported License.
  • 12. Programming OO • Know the differences between the interface and the implementation • Think abstractly • Give users of my objects the minimal interface possible • And…. – Know the design principles – Reuse knowledge (Patterns) OO Programming - Introduction is licensed under a Creative Commons Attribution- 12 NonCommercial-ShareAlike 3.0 Unported License.
  • 13. Programming OO • Know the differences between the interface and the implementation • Think abstractly • Give users of my objects the minimal interface possible OO Programming - Introduction is licensed under a Creative Commons Attribution- 13 NonCommercial-ShareAlike 3.0 Unported License.
  • 14. Programming OO Interface and Implementation interface Services that my objects expose to my object’s clients public class Computer { private PowerSupply powerSupply; public void turnOn() { turnOnPowerSupply(); } public void turnOff() { turnOffPowerSupply(); } private void turnOffPowerSupply() { powerSupply.turnOff(); } private void turnOnPowerSupply() { powerSupply.turnOn(); } } OO Programming - Introduction is licensed under a Creative Commons Attribution- 14 NonCommercial-ShareAlike 3.0 Unported License.
  • 15. Programming OO Interface and Implementation implementation Implementation is how the object realize the services expected by the clients public class Computer { private PowerSupply powerSupply; public void turnOn() { turnOnPowerSupply(); } public void turnOff() { turnOffPowerSupply(); } private void turnOffPowerSupply() { powerSupply.turnOff(); } private void turnOnPowerSupply() { powerSupply.turnOn(); } } OO Programming - Introduction is licensed under a Creative Commons Attribution- 15 NonCommercial-ShareAlike 3.0 Unported License.
  • 16. Programming OO Interface and Implementation • Object’s clients can be other objects OO Programming - Introduction is licensed under a Creative Commons Attribution- 16 NonCommercial-ShareAlike 3.0 Unported License.
  • 17. Programming OO Interface and Implementation • If an implementation change, clients don’t care, as long as the interface provides them the service they expect public class Computer { public void turnOn() { PowerSupply.on(); } public void turnOff() { PowerSupply.off(); }} OO Programming - Introduction is licensed under a Creative Commons Attribution- 17 NonCommercial-ShareAlike 3.0 Unported License.
  • 18. Programming OO • Know the differences between the interface and the implementation • Think abstractly • Give users of my objects the minimal interface possible OO Programming - Introduction is licensed under a Creative Commons Attribution- 18 NonCommercial-ShareAlike 3.0 Unported License.
  • 19. Programming OO Think Abstractly • Design interfaces as abstract as possible • Abstraction allows reuse • Foundation of many design guidelines OO Programming - Introduction is licensed under a Creative Commons Attribution- 19 NonCommercial-ShareAlike 3.0 Unported License.
  • 20. Programming OO Think Abstractly Which interface is more abstract? 1 public class Computer { public void positionDiskHead(int sector) { } public void startDiskRotation() { } public Byte[] readBytes(int endSector) { } public void endDiskRotation() { } } 2 public class Computer { public Byte[] readFromMedium(MediumIdentifier id, ReadInstructions instructions) { return null; } } OO Programming - Introduction is licensed under a Creative Commons Attribution- 20 NonCommercial-ShareAlike 3.0 Unported License.
  • 21. Programming OO Think Abstractly Which interface is more reusable? 1 public class Computer { public void positionDiskHead(int sector) { } public void startDiskRotation() { } public Byte[] readBytes(int endSector) { } public void endDiskRotation() { } } 2 public class Computer { public Byte[] readFromMedium(MediumIdentifier id, ReadInstructions instructions) { return null; } } OO Programming - Introduction is licensed under a Creative Commons Attribution- 21 NonCommercial-ShareAlike 3.0 Unported License.
  • 22. Programming OO • Know the differences between the interface and the implementation • Think abstractly • Give users of my objects the minimal interface possible OO Programming - Introduction is licensed under a Creative Commons Attribution- 22 NonCommercial-ShareAlike 3.0 Unported License.
  • 23. You Ain’t Programming OO Gonna Need It Minimal interface • Tend to follow the YAGNI principle • Give clients only the strictly needed interfaces • Only add new interfaces if object’s clients really require it OO Programming - Introduction is licensed under a Creative Commons Attribution- 23 NonCommercial-ShareAlike 3.0 Unported License.
  • 24. Programming OO Minimal interface I give this interface to the client of my object. (In reality, I’m giving no 1 interface at all) public class Computer { } 2 The client asks, “Hey, now what? How do I turn it on?” I give an interface to allow the client to turn on the computer 3 public class Computer { public void turnOn() {} } 4 The client then asks, “Thanks, but… How do I turn it off?” 5 Story goes on… OO Programming - Introduction is licensed under a Creative Commons Attribution- 24 NonCommercial-ShareAlike 3.0 Unported License.
  • 25. OO Concepts • Encapsulation and Data Hiding • Inheritance • Polymorphism • Composition OO Programming - Introduction is licensed under a Creative Commons Attribution- 25 NonCommercial-ShareAlike 3.0 Unported License.
  • 26. OO Concepts Encapsulation and Data Hiding • Hide implementation details, such as state and behavior pertaining only the implementation of interface. • Give users only access to interfaces public class Computer { private PowerSupply powerSupply; public void turnOn() { What a user see turnOnPowerSupply(); } public void turnOff() { turnOffPowerSupply(); } public class Computer { public void turnOn() { private void turnOffPowerSupply() { turnOnPowerSupply(); powerSupply.turnOff(); } } public void turnOff() { private void turnOnPowerSupply() { turnOffPowerSupply(); powerSupply.turnOn(); } } } } OO Programming - Introduction is licensed under a Creative Commons Attribution- 26 NonCommercial-ShareAlike 3.0 Unported License.
  • 27. OO Concepts Inheritance • Allows me to reuse code by abstracting common behavior and state of a set of classes OO Programming - Introduction is licensed under a Creative Commons Attribution- 27 NonCommercial-ShareAlike 3.0 Unported License.
  • 28. OO Concepts Polymorphism • I can have a have a type that assumes multiple forms ElectronicEquipment computer = new Computer(); ElectronicEquipment phone = new Phone(); computer.turnOn(); phone.turnOn(); • An ElectronicEquipment can assume the form of a Computer or a Phone • A user with a reference to an ElectronicEquipment don’t care if it’s a Computer or a Phone OO Programming - Introduction is licensed under a Creative Commons Attribution- 28 NonCommercial-ShareAlike 3.0 Unported License.
  • 29. OO Concepts Composition • Can reuse code by factor in common behavior and state to a separate class and use that class as a building block of other classes. – Both Printer and Computer have a PowerSupply and a motherborad. OO Programming - Introduction is licensed under a Creative Commons Attribution- 29 NonCommercial-ShareAlike 3.0 Unported License.
  • 30. João Pereira March 2012 OO Design Principles - Introduction by João Miguel Pereira is licensed under a Creative Commons Attribution- NonCommercial-ShareAlike 3.0 Unported License.