DOC PREVIEW
UCSC CMPS 20 - Inheritance, Method Overloading, Interfaces, Abstract Classes

This preview shows page 1-2-3-4-5-6 out of 18 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 18 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Inheritance, Method Overloading, Interfaces, Abstract ClassesAnnouncementsClassificationDeveloping classesAbstraction and Classification is trickyHierarchies of CategoriesRepresenting Abstract CategoriesInterfaceDefining an interfaceUsing an InterfaceAbstract ClassesAbstract vs Virtual MethodsExample of Abstract and Virtual MethodsOverriding methodsInterface vs Abstract ClassInterface vs Abstract Class (cont’d)Interface vs Abstract class (cont’d)HomeworkInheritance, Method Overloading, Interfaces, Abstract ClassesGame Design ExperienceProfessor Jim WhiteheadJanuary 28, 2009Creative Commons Attribution 3.0creativecommons.org/licenses/by/3.0Announcements•Homework #1 back Friday►Was unable to connect with TAs yesterday•Work breakdown and schedule►Due next Monday►Team assignment►Goals: •Develop an understanding of work needed to be performed to complete project, and time required•Discuss breakdown of tasks among partnersClassification•Classification is the act of assigning things to categories of things.►The is-a relationship•Examples:►A Volkwagen Jetta is a (kind of) car.►A hot dog is a (kind of) food.•Classification is at the heart of object-oriented modeling.►An object-oriented class represents a category•Class car, Class food►Object instances (in OO) are instances of categoriesDeveloping classes•The process of taking a set of real world objects and developing its associated category is called abstraction.•Example:►If I give you the set of food items:•Cheese whizz, hot dog, corn chips, bran flakes, chicken►The act by which you create the category food and call these all examples of food, is abstraction.•The process of abstraction is used to determine what classes should be in your softwareAbstraction and Classification is tricky•Consider the following items. Which ones do you consider to be furniture?►Sofa►Recliner►Television►Stove►Counter-top microwave oven►Fixed line telephone•Qualities of categories►Fuzzy boundaries►Some category members are better examples of the category than others►Categories often best understood in contrast to other categories•Dividing line between furniture and kitchen appliances►Women, Fire, Dangerous Things, George Lakoff•Book on categorizationHierarchies of Categories•Sometimes there are situations where you have multiple levels of categories►Category1 is a (kind of) Category2 is a (kind of) Category3►Example•A cell phone is a (kind of) telephone•A wired phone is a (kind of) telephone•An iPhone is a (kind of) cell phone•Telephone is an abstract category•In software, may want to represent things like telephone, but never have direct instances►Only want instances of sub-categories►Example: want to represent telephones, but do not want instances of telephone. Only want instances of cell phone, or wired phone.►In software, we would like telephone to provide details about all telephones…•All phones have a telephone number, can make and receive calls► …but not to give cell phone or wired-phone specific information•Cell phones have text messaging, wired phones do notRepresenting Abstract Categories•Two ways to represent abstract categories►Interface•Class properties•Method names and parameter lists, but no method implementations of any methods.►Abstract Class•Class variables•Can have a mixture of:–Methods that are fully implemented»Might (or might not) be overridden in subclasses–Methods that only have a name and a parameter list»Abstract method»Must be implemented in subclassesInterface•Describes a set of methods, properties that must be implemented by all subclasses►But, no implementation details are given►Subclasses can implement the methods and properties as they see fit•So long as they match the types of the properties, method return values, and method parameters•Describes the external boundary of class►What other classes need to know to use its features►Provides no implementation detailDefining an interface•Naming convention:►Put capital “I” in front of interface name[attributes] [access-modifiers] inter face identifier [:base-interface(s)]{ interface-body }Simple example:interface ITelephone{ public string PhoneNum {get; set;} // Phone number property, can read and write void display_phone_num(); // Output phone number}Using an Interface•Syntactically, looks like inheritance•Must implement all aspects of interfaceinterface ITelephone{ public string PhoneNum {get; set;} // Phone number property, can read and write void display_phone_num(); // Output phone number}public cellphone : ITelephone{public string PhoneNum {get; set;} // Use automatic property to implement interface propertypublic void display_phone_num() { System.Console.WriteLine(“cell phone number is {0}”, PhoneNum); }}Abstract Classes•Sometimes you want to:►Define the information passing interface for a class•Can do this with an interface►And provide implementations for some simple methods that all subclasses are likely to use, while only providing interfaces for some other methods which subclasses must implement•Cannot use an interface for this•Define an abstract class instead•An abstract class looks like a regular class, except►Some methods are marked abstract and some are marked or virtualAbstract vs Virtual Methods•An abstract method►Only the name, return type, and parameter list is provided►There is no implementation – subclasses must implement►Must use override keyword in implementing method•A virtual method►The entire method is implemented•Have name, return type, parameter list, and implementing statements►Use of virtual keyword signifies that subclasses are welcome to override►Subclasses may provide new implementation, but are not required to do so•If they do, must use override keywordExample of Abstract and Virtual Methodsclass Telephone{ public string PhoneNum {get; set;} // Phone number property, can read and write virtual void display_phone_num() // Output phone number, might be overridden by subclasses { System.Console.WriteLine(“Telephone number is {0}”, PhoneNum); } abstract bool call(string num_to_call); // Abstract class, must be implemented by subclasses}public cellphone : Telephone{public override void display_phone_num() // Overrides implementation in Telephone {


View Full Document

UCSC CMPS 20 - Inheritance, Method Overloading, Interfaces, Abstract Classes

Documents in this Course
Load more
Download Inheritance, Method Overloading, Interfaces, Abstract Classes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Inheritance, Method Overloading, Interfaces, Abstract Classes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Inheritance, Method Overloading, Interfaces, Abstract Classes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?