Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Object???Oriented Programming with Swift 2

You're reading from  Object???Oriented Programming with Swift 2

Product type Book
Published in Jan 2016
Publisher
ISBN-13 9781785885693
Pages 332 pages
Edition 1st Edition
Languages
Author (1):
Gaston C. Hillar Gaston C. Hillar
Profile icon Gaston C. Hillar

Table of Contents (16) Chapters

Object–Oriented Programming with Swift 2
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Objects from the Real World to Playground 2. Structures, Classes, and Instances 3. Encapsulation of Data with Properties 4. Inheritance, Abstraction, and Specialization 5. Contract Programming with Protocols 6. Maximization of Code Reuse with Generic Code 7. Object-Oriented Programming and Functional Programming 8. Extending and Building Object-Oriented Code Exercise Answers Index

Understanding how protocols work in combination with classes


We have to work with two different types of characters: comic and game characters. A comic character has a nickname and must be able to draw speech balloons and thought balloons. The speech balloon might have another comic character as a destination.

A game character has a full name and must be able to perform the following tasks:

  • Draw itself in a specific 2D position indicated by the x and y coordinates

  • Move itself to a specific 2D position indicated by the x and y coordinates

  • Check whether it intersects with another game character

We will work with objects that can be both a comic character and a game character. However, we will also work with objects that will just be either a comic or game character. Neither the game nor the comic character has a generic way of performing the previously described tasks. Thus, each object that declares itself as a comic character must define the tasks related to speech and thought balloons. Each...

lock icon The rest of the chapter is locked
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 €14.99/month. Cancel anytime}