DOC PREVIEW
TRINITY CSCI 1321 - Inheritance and Subtyping

This preview shows page 1-2-3 out of 9 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 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 9 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 9 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Inheritance and Subtyping1-19-2011Opening DiscussionMinute Essay CommentsSwitching editors. “:w” in your Eclipse files.Autoformatting and being “helpful”.The purpose of packages.Solutions to the IcP.Special MethodsapplyIf you have an apply method, it will be called when you use an object in a function like syntax.This is how you index into collections.c(i) is the same as c.apply(i)updateTakes two arguments and gives you assignment into an index.c(i)=o is the same as c.update(i,o)More Special MethodsSymbolic OperatorsYou can use symbolic method names.If they take only one argument you can use them as operators.Property AssignmentA method name that ends in _= and takes a single argument is interpreted and creating an assignment to a member.Public vars actually compile to a private var and an accessor method with an assignment method.PolymorphismLiterally this means many shapes.In programming it means many types.The code we wrote in the first semester was generally monomorphic. It worked for one type.Polymorphic code is much more powerful. You write it once and it works for lots of types.A lot of this semester and the benefit of OO is about abstraction and polymorphism.Universal polymorphism mean code can work with an infinite number of types.SubtypingIf type B is a subtype of type A, then anyplace in the code that requires type A, you can provide an object of type B.This gives us a form of Universal polymorphism called inclusion polymorphism.AnyAnyRefAnyValNullNothingDoubleFloatLongIntShortByteUnitBooleanCharStringSeqListArrayOther ClassesInheritanceThe way we get inheritance in Scala (and most class based OOPLs) is through inheritance.If B inherits from A it becomes a subtype of A.B also gets all the members (data and functions) of A. This is effectively why it is a subtype. Anything you could do to A you can do to B because B got it all from A.You can only inherit from one class and you do so with the extends keyword.class B extends A { ... }OverridingPart of the real power of inheritance comes from the fact that you can override methods.An overridden declaration is one in the subclass with the same name and type as the superclass. Methods need to match arguments as well.You must label overriding members with the keyword override. We did this for paint last semester.toString is a good method to override.Minute EssayQuestions?If you use a local copy of the book, remember to pull it down occasionally so you get


View Full Document

TRINITY CSCI 1321 - Inheritance and Subtyping

Documents in this Course
Recursion

Recursion

11 pages

Iterators

Iterators

10 pages

Actors

Actors

9 pages

Recursion

Recursion

15 pages

Recursion

Recursion

10 pages

Threads

Threads

7 pages

Trees

Trees

11 pages

Load more
Download Inheritance and Subtyping
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 and Subtyping 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 and Subtyping 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?