Hands-On Object-Oriented Programming with C#

Book description

Enhance your programming skills by learning the intricacies of object oriented programming in C# 8

Key Features

  • Understand the four pillars of OOP; encapsulation, inheritance, abstraction and polymorphism
  • Leverage the latest features of C# 8 including nullable reference types and Async Streams
  • Explore various design patterns, principles, and best practices in OOP

Book Description

Object-oriented programming (OOP) is a programming paradigm organized around objects rather than actions, and data rather than logic. With the latest release of C#, you can look forward to new additions that improve object-oriented programming.

This book will get you up to speed with OOP in C# in an engaging and interactive way. The book starts off by introducing you to C# language essentials and explaining OOP concepts through simple programs. You will then go on to learn how to use classes, interfacesm and properties to write pure OOP code in your applications. You will broaden your understanding of OOP further as you delve into some of the advanced features of the language, such as using events, delegates, and generics. Next, you will learn the secrets of writing good code by following design patterns and design principles. You'll also understand problem statements with their solutions and learn how to work with databases with the help of ADO.NET. Further on, you'll discover a chapter dedicated to the Git version control system. As you approach the conclusion, you'll be able to work through OOP-specific interview questions and understand how to tackle them.

By the end of this book, you will have a good understanding of OOP with C# and be able to take your skills to the next level.

What you will learn

  • Master OOP paradigm fundamentals
  • Explore various types of exceptions
  • Utilize C# language constructs efficiently
  • Solve complex design problems by understanding OOP
  • Understand how to work with databases using ADO.NET
  • Understand the power of generics in C#
  • Get insights into the popular version control system, Git
  • Learn how to model and design your software

Who this book is for

This book is designed for people who are new to object-oriented programming. Basic C# skills are assumed, however, prior knowledge of OOP in any other language is not required.

Table of contents

  1. Title Page
  2. Copyright and Credits
    1. Hands-On Object-Oriented Programming with C#
  3. About Packt
    1. Why subscribe?
    2. Packt.com
  4. Contributors
    1. About the author
    2. About the reviewer
    3. Packt is searching for authors like you
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Get in touch
      1. Reviews
  6. Overview of C# as a Language
    1. Evolution of C#
      1. Managed code
      2. Generics
      3. LINQ
      4. Dynamics
      5. Async/await
      6. Compiler as a service
      7. Exception filters
      8. C# 8 and beyond
    2. Architecture of .NET
      1. Common Language Runtime
      2. Common Type System
      3. .NET framework class libraries
      4. Just-in-time compiler
    3. Fundamentals and syntax of C# language
      1. Data types
      2. Nullable types
      3. Literals
        1. Boolean
        2. Integer
        3. Real
        4. Character
        5. String
      4. Programming syntax – conditions
        1. If-else construct
        2. Switch-case construct
        3. goto statements
      5. Programming syntax – loops
        1. The while construct
        2. The do-while construct
        3. The for construct
        4. The foreach construct
        5. Contextual – break and continue statements
          1. Break
          2. Continue
    4. Writing your first C# program in a console application
    5. Visual Studio as an editor
      1. Evolution of Visual Studio
      2. Types of Visual Studio
        1. Visual Studio Community
        2. Visual Studio Professional
        3. Visual Studio Enterprise
        4. Visual Studio Code
      3. Introduction to the Visual Studio IDE
        1. New Project
          1. Solution Explorer
          2. Main workspace area
          3. Output window
          4. The Command and Immediate windows
          5. Search option in IDE
    6. Writing your first program in Visual Studio
      1. How to debug
      2. Debugging through code
    7. Summary
  7. Hello OOP - Classes and Objects
    1. Classes in OOP
      1. The general form of a class
      2. Writing a simple class
    2. Objects in OOP
      1. How to create objects
    3. Variables in C#
    4. Methods in a class
      1. Creating a method
      2. Constructor of a class
    5. Characteristics of OOP
      1. Inheritance
      2. Encapsulation
      3. Abstraction
      4. Polymorphism
    6. Summary
  8. Implementation of OOP in C#
    1. Interfaces
    2. The abstract class
    3. The partial class
    4. The sealed class
    5. Tuples
    6. Properties
    7. Access specifiers for classes
      1. Public
      2. Private
      3. Internal
      4. Protected
      5. Protected internal
    8. Summary
  9. Object Collaboration
    1. Examples of object collaboration
    2. Different types of object collaboration in C#
      1. Case study
      2. Dependency
      3. Association
        1. Aggregation
        2. Composition
      4. Inheritance
    3. Summary
  10. Exception Handling
    1. Why we need exception handling in programming
      1. Exception handling in C# programming
    2. Basics of exception handling
    3. Try and catch
    4. What happens if you don't handle exceptions?
    5. Multiple catch blocks
    6. Using the throw keyword
    7. What does the finally block do?
    8. Exception class
      1. Some common exception classes
    9. User-defined exceptions
    10. The exception filter
    11. Exception handling best practices
    12. Summary
  11. Events and Delegates
    1. What is a delegate?
      1. How to create and use delegates
    2. Method group conversion
      1. Using the static and instance methods as delegates
    3. Multicasting
    4. Covariance and contravariance
    5. Events
      1. Multicasting events
      2. Event guidelines from .NET
    6. Summary
  12. Generics in C#
    1. What are generics?
    2. Why do we need generics?
    3. Different constraints of generics
      1. Base class constraints
      2. Interface constraints
      3. Reference type and value type constraints
      4. Multiple constraints
    4. Generic methods
      1. Type-inferencing
    5. Covariance and contravariance in generics
      1. Covariance
      2. Contravariance
    6. Summary
  13. Modeling and Designing Software
    1. The importance of design diagrams
      1. Different UML diagrams
    2. Class diagrams
      1. Inheritance
      2. Association
      3. Aggregation
      4. Composition
      5. Dependency
      6. An example of a class diagram
    3. Use case diagrams
      1. The actor
      2. The use case
      3. The communication link
      4. The system boundaries
      5. An example of a use case diagram
    4. A sequence diagram
      1. An actor
      2. A lifeline
      3. An activation
      4. A call message
      5. A return message
      6. A self message
      7. A recursive message
      8. A create message
      9. A destroy message
      10. A duration message
      11. A note
      12. An example of a sequence diagram
    5. Summary
  14. Visual Studio and Associated Tools
    1. Visual Studio project types and templates
    2. Visual Studio Editor and different windows
      1. Editor window
      2. Solution Explorer
      3. Output window
    3. Debugging windows
      1. Breakpoints window
      2. Exception Settings
      3. Output
      4. Diagnostic Tools
      5. Immediate window
      6. Python debugger window
    4. Breakpoints, Call Stack Trace, and Watch
      1. Breakpoint
      2. Call Stack Trace
      3. Watch window
    5. Git in Visual Studio
    6. Refactoring and code-optimization techniques
      1. Rename
      2. Changing the method signature
      3. Encapsulate Field
      4. Extract Method
    7. Summary
  15. Exploring ADO.NET with Examples
    1. The fundamentals of ADO.NET
      1. Data providers
        1. Connection objects
        2. The Command object
        3. The DataReader object
        4. DataAdapter
    2. Connecting to various databases
      1. SQL Server
      2. The Oracle database
    3. Working with DataReaders and DataAdapters
      1. DataReaders
      2. DataAdapters
    4. Working with stored procedures
    5. Working with the Entity Framework
      1. What is an entity in the Entity Framework?
      2. Different types of Entity properties
        1. Scalar properties
        2. Navigation properties
      3. The code-first approach
      4. The database-first approach
      5. Using the Entity Framework
    6. Transactions in SQL
      1. Atomic
      2. Consistent
      3. Isolated
      4. Durable
    7. Summary
  16. New Features in C# 8
    1. Environment Setup
    2. Nullable reference types
    3. Async streams
    4. Ranges and indices
    5. Default implementation of interface members
    6. Switch expressions
    7. Target-typed new expressions
    8. Summary
  17. Understanding Design Patterns and Principles
    1. Design principles
      1. The single responsibility principle
      2. The open-closed principle
      3. The Liskov substitution principle
      4. The interface segregation principle
      5. The dependency inversion principle
    2. Creational design patterns
      1. The abstract factory pattern
      2. The builder pattern
      3. The factory method pattern
      4. The prototype pattern
      5. The singleton pattern
    3. Structural design patterns
      1. The adapter pattern
      2. The decorator pattern
      3. The facade pattern
      4. The proxy pattern
    4. Behavioral design patterns
      1. The command pattern
      2. The observer pattern
      3. The strategy pattern
    5. The MVC pattern
    6. Summary
  18. Git - The Version Control System
    1. What is version control?
    2. How Git works
      1. Modified
      2. Staged
      3. Committed
    3. Installing Git on Windows
    4. The basics of Git
      1. Git config
      2. Git init
      3. Git clone
      4. Git status
      5. Git add
      6. Git commit
      7. Git log
      8. Git remote
      9. Git push
      10. Git pull
      11. Git fetch
    5. Branching in Git
      1. Creating a branch
      2. Viewing available branches
      3. Changing branches
      4. Deleting a branch
      5. Merging in Git
    6. Summary
  19. Prepare Yourself - Interviews and the Future
    1. Interview questions
      1. What are the fundamental principles of object-oriented programming?
      2. What is inheritance?
      3. What is encapsulation?
      4. What is abstraction?
      5. What is polymorphism?
      6. What is an interface?
      7. What is an abstract class?
      8. What is a sealed class?
      9. What is a partial class?
      10. What are the differences between interfaces and abstract classes?
      11. What is the difference between method-overloading and method-overriding?
      12. What are access modifiers?
      13. What is boxing and unboxing?
      14. What are the differences between a struct and a class?
      15. What is an extension method in C# and how do we use it?
      16. What is managed and unmanaged code?
      17. What is a virtual method in C#?
      18. What do you understand by value types and reference types in C#.NET?
      19. What are design principles?
      20. What is the single responsibility principle?
      21. What is the Open/Closed principle?
      22. What is the Liskov substitution principle?
      23. What is the interface segregation principle?
      24. What is the dependency inversion principle?
    2. Interview and career tips
      1. Improving your communication skills
      2. Keep practicing
    3. Things to learn next
    4. Building the habit of reading
    5. Summary
  20. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: Hands-On Object-Oriented Programming with C#
  • Author(s): Raihan Taher
  • Release date: February 2019
  • Publisher(s): Packt Publishing
  • ISBN: 9781788296229