Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Learning Object-Oriented Programming

You're reading from   Learning Object-Oriented Programming Explore and crack the OOP code in Python, JavaScript, and C#

Arrow left icon
Product type Paperback
Published in Jul 2015
Publisher
ISBN-13 9781785289637
Length 280 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Gaston C. Hillar Gaston C. Hillar
Author Profile Icon Gaston C. Hillar
Gaston C. Hillar
Arrow right icon
View More author details
Toc

Table of Contents (10) Chapters Close

Preface 1. Objects Everywhere FREE CHAPTER 2. Classes and Instances 3. Encapsulation of Data 4. Inheritance and Specialization 5. Interfaces, Multiple Inheritance, and Composition 6. Duck Typing and Generics 7. Organization of Object-Oriented Code 8. Taking Full Advantage of Object-Oriented Programming Index

Working with generics in C#


We will create an IAnimal interface to specify the requirements that a type must meet in order to be considered an animal. We will create the Animal abstract base class that implements this interface. Then, we will specialize this class in two subclasses: Dog and Frog. Later, we will create the Party class that will be able to work with instances of any class that implements the IAnimal interface through generics. We will work with the party of dogs and frogs.

Now, we will create an IDeeJay interface and implement it in a HorseDeeJay class. We will also create a subclass of the Party class named PartyWithDeeJay that will use generics to work with instances of any type that implement the IAnimal interface and instances of any type that implements the IDeeJay interface. Then, we will work with the party of dogs with a DJ.

Declaring an interface to be used as a constraint

Now, it is time to code one of the interfaces that will be used as a constraint later when we...

lock icon The rest of the chapter is locked
Visually different images
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Learning Object-Oriented Programming
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime
Modal Close icon
Modal Close icon