presentationWeek2

presentationWeek2 - Week two some details about...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Week two, some details about polymorphism, encapsulation, etc. Wednesday, September 21, 2011 Upcoming topics . .. • encapsulation and polymorphism • in C++ • in Java • Constructors • in C++ • in Java • Controlling inheritance and what is inherited (0204) • in C++ • in Java • program structure - how to use this to design better programs (0105) Wednesday, September 21, 2011 Encapsulation and polymorphism Wednesday, September 21, 2011 YHL Encapsulation and Polymorphism 4 Interfaces should be implementation independent • If you need a student GPA from some call, you don’t care how it is computed – Could be pre-computed and stored as a fixed decimal i.dd – Could be computed from a transcript – Could be computed from “total hours” and “total credits” fields – . . . • But, if you want a GPA, all you really care about is that you get a GPA • You do not need to know how the Student class implements the method -- you only need the interface to get the method from a student object Wednesday, September 21, 2011 YHL Encapsulation and Polymorphism 5 Interface vs Implementation • Suppose you are creating a class to support searching for books in a library – When the library has only hundreds of books, you can use a list to store each book (author, title, year . ..) – As the number of books grows, you may need to use a more sophisticated indexing scheme or SQL . ... • The class should provides the same interface to search books. • Users of functionality provided by the class should not care how the search is implemented, only that it is and that they don’t have to change their code when your class changes its implementation • Encapsulation is enforced by compilers (no run-time surprises). Wednesday, September 21, 2011 YHL Encapsulation and Polymorphism 6 Interface • A class' public attributes and methods form the interface for the objects of this class and all derived classes. • If func is a public method, the object must be able to respond to a call of func as defined by the specification for the class. – This is a "promise" that cannot be withdrawn – the specification is often informal (i.e. documentation or a manual) -- it is rarely a formal, executable thing • Code reuse ⇒ A promise cannot be withdrawn. • Anything not in the interface (private attributes and methods) can be changed – Provides flexibility to the class designer in implementation and maintenance – If you try and break this you are a baaad (as in not good) programmer • Keep an interface as small as possible . Make only the essential functionalities visible. Hide all details. Wednesday, September 21, 2011 YHL Encapsulation and Polymorphism 7 Why Encapsulation?...
View Full Document

This note was uploaded on 02/19/2012 for the course ECE 462 taught by Professor Samuelmidkiff during the Fall '11 term at Purdue.

Page1 / 92

presentationWeek2 - Week two some details about...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online