You are previewing Learning Object-Oriented Programming.
O'Reilly logo
Learning Object-Oriented Programming

Book Description

Explore and crack the OOP code in Python, JavaScript, and C#

In Detail

Learning Object-Oriented Programming is an easy-to-follow guide full of hands-on examples of solutions to common problems with object-oriented code in Python, JavaScript, and C#. It starts by helping you to recognize objects from real-life scenarios and demonstrates that working with them makes it simpler to write code that is easy to understand and reuse. You will learn to protect and hide data with the data encapsulation features of Python, JavaScript, and C#.

You will explore how to maximize code reuse by writing code capable of working with objects of different types, and discover the advantage of duck typing in both Python and JavaScript, while you work with interfaces and generics in C#. With a fair understanding of interfaces, multiple inheritance, and composition, you will move on to refactor existing code and to organize your source for easy maintenance and extension.

Learning Object-Oriented Programming will help you to make better, stronger, and reusable code.

What You Will Learn

  • Generate instances in three programming languages: Python, JavaScript, and C#

  • Customize constructors and destructors

  • Work with a combination of access modifiers, prefixes, properties, fields, attributes, and local variables to encapsulate and hide data

  • Take advantage of specialization and the possibility to overload or override members

  • Create reusable and easier to maintain code

  • Use interfaces, generics, and multiple inheritance when available

  • Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

    Table of Contents

    1. Learning Object-Oriented Programming
      1. Table of Contents
      2. Learning Object-Oriented Programming
      3. Credits
      4. About the Author
      5. Acknowledgments
      6. About the Reviewers
      7. www.PacktPub.com
        1. Support files, eBooks, discount offers, and more
          1. Why subscribe?
          2. Free access for Packt account holders
      8. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. eBooks, discount offers, and more
          5. Questions
      9. 1. Objects Everywhere
        1. Recognizing objects from nouns
        2. Generating blueprints for objects
        3. Recognizing attributes/fields
        4. Recognizing actions from verbs – methods
        5. Organizing the blueprints – classes
        6. Object-oriented approaches in Python, JavaScript, and C#
        7. Summary
      10. 2. Classes and Instances
        1. Understanding classes and instances
        2. Understanding constructors and destructors
        3. Declaring classes in Python
        4. Customizing constructors in Python
        5. Customizing destructors in Python
        6. Creating instances of classes in Python
        7. Declaring classes in C#
        8. Customizing constructors in C#
        9. Customizing destructors in C#
        10. Creating instances of classes in C#
        11. Understanding that functions are objects in JavaScript
        12. Working with constructor functions in JavaScript
        13. Creating instances in JavaScript
        14. Summary
      11. 3. Encapsulation of Data
        1. Understanding the different members of a class
        2. Protecting and hiding data
        3. Working with properties
        4. Understanding the difference between mutability and immutability
        5. Encapsulating data in Python
          1. Adding attributes to a class
          2. Hiding data in Python using prefixes
          3. Using property getters and setters in Python
          4. Using methods to add behaviors to classes in Python
        6. Encapsulating data in C#
          1. Adding fields to a class
          2. Using access modifiers
          3. Using property getters and setters in C#
          4. Working with auto-implemented properties
          5. Using methods to add behaviors to classes in C#
        7. Encapsulating data in JavaScript
          1. Adding properties to a constructor function
          2. Hiding data in JavaScript with local variables
          3. Using property getters and setters in JavaScript
          4. Using methods to add behaviors to constructor functions
        8. Summary
      12. 4. Inheritance and Specialization
        1. Using classes to abstract behavior
        2. Understanding inheritance
        3. Understanding method overloading and overriding
        4. Understanding operator overloading
        5. Taking advantage of polymorphism
        6. Working with simple inheritance in Python
          1. Creating classes that specialize behavior in Python
          2. Using simple inheritance in Python
          3. Overriding methods in Python
          4. Overloading operators in Python
          5. Understanding polymorphism in Python
        7. Working with simple inheritance in C#
          1. Creating classes that specialize behavior in C#
          2. Using simple inheritance in C#
          3. Overloading and overriding methods in C#
          4. Overloading operators in C#
          5. Understanding polymorphism in C#
        8. Working with the prototype-based inheritance in JavaScript
          1. Creating objects that specialize behavior in JavaScript
          2. Using the prototype-based inheritance in JavaScript
          3. Overriding methods in JavaScript
          4. Overloading operators in JavaScript
          5. Understanding polymorphism in JavaScript
        9. Summary
      13. 5. Interfaces, Multiple Inheritance, and Composition
        1. Understanding the requirement to work with multiple base classes
        2. Working with multiple inheritance in Python
          1. Declaring base classes for multiple inheritance
          2. Declaring classes that override methods
          3. Declaring a class with multiple base classes
          4. Working with instances of classes that use multiple inheritance
          5. Working with abstract base classes
        3. Interfaces and multiple inheritance in C#
          1. Declaring interfaces
          2. Declaring classes that implement interfaces
          3. Working with multiple inheritance
          4. Working with methods that receive interfaces as arguments
        4. Working with composition in JavaScript
          1. Declaring base constructor functions for composition
          2. Declaring constructor functions that use composition
          3. Working with an object composed of many objects
          4. Working with instances composed of many objects
        5. Summary
      14. 6. Duck Typing and Generics
        1. Understanding parametric polymorphism and duck typing
        2. Working with duck typing in Python
          1. Declaring a base class that defines the generic behavior
          2. Declaring subclasses for duck typing
          3. Declaring a class that works with duck typing
          4. Using a generic class for multiple types
          5. Working with duck typing in mind
        3. Working with generics in C#
          1. Declaring an interface to be used as a constraint
          2. Declaring an abstract base class that implements two interfaces
          3. Declaring subclasses of an abstract base class
          4. Declaring a class that works with a constrained generic type
          5. Using a generic class for multiple types
          6. Declaring a class that works with two constrained generic types
          7. Using a generic class with two generic type parameters
        4. Working with duck typing in JavaScript
          1. Declaring a constructor function that defines the generic behavior
          2. Working with the prototype chain and duck typing
          3. Declaring methods that work with duck typing
          4. Using generic methods for multiple objects
          5. Working with duck typing in mind
        5. Summary
      15. 7. Organization of Object-Oriented Code
        1. Thinking about the best ways to organize code
        2. Organizing object-oriented code in Python
          1. Working with source files organized in folders
          2. Importing modules
          3. Working with module hierarchies
        3. Organizing object-oriented code in C#
          1. Working with folders
          2. Using namespaces
          3. Working with namespace hierarchies in C#
        4. Organizing object-oriented code in JavaScript
          1. Working with objects to organize code
          2. Declaring constructor functions within objects
          3. Working with nested objects that organize code
        5. Summary
      16. 8. Taking Full Advantage of Object-Oriented Programming
        1. Putting together all the pieces of the object-oriented puzzle
        2. Refactoring existing code in Python
        3. Refactoring existing code in C#
        4. Refactoring existing code in JavaScript
        5. Summary
      17. Index