lec10Classes - Lecture 10 classes and objects As we make...

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

View Full Document Right Arrow Icon
Lecture 10 – classes and objects As we make larger programs, we saw that methods gave us two things. 1) Organization 2) Compact code – write code once, call many times Eventually, the programs get too large even for methods. We want another way to break down complex problems. We have some other goals, too. The goals of object-oriented programming are: 1) Organization – divide a complex program into small parts in order to make programs easier to design and implement 2) Code Reuse – Package tasks into data + operation sets in such a way that each unit is usable in many programs, not just this particular program. 3) Information-hiding – provide an interface, but hide the details of the implementation, so that programmers only need to know the parts that are relevant to them. This makes code easier to use by others. For example, we have been using the Scanner. The job of the Scanner is to read input from the keyboard (or a file) and allow a program to access it in a nice interface. Reading from the screen is not something that I know how to do directly – the Scanner class provides all of the items above. First, it is code reuse, because each programmer need not write the code for reading from the user. They can all use the code that one person wrote. Second, the programmers who use the Scanner class have no idea how it is implemented. We just look at the interface – the sets of methods – in order to complete the task. That way, it is much simpler for us. Finally, it is good organization. I don’t have any of the code for reading in from the screen cluttering my program. In just one line, I can read an item from the screen, and it is very easy to read. So we would like more such items.
Background image of page 1

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

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

This note was uploaded on 12/27/2011 for the course CMPSC 5 taught by Professor Franklin during the Fall '09 term at UCSB.

Page1 / 3

lec10Classes - Lecture 10 classes and objects As we make...

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

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