{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

csc2700lect01

csc2700lect01 - CSc 2700 Lecture 0 1 Interfaces August 26...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CSc 2700: Lecture # 0 & # 1 Interfaces August 26 & 28, 2008 1 Administrative Matters ( Discussion on class policies, syllabus, Netbeans, archiving of files and using blackboard. ) 2 Introduction The concept of interface has its origin in the C language. Interfaces were historically derived from the header files of the C programming language by restricting their syntactic context and contents, and making them a part of the language semantics. An interface is fundamental to modular program- ming. Typically, we want to separate the interface of a class, what it does, from the implementation of the class, how it does it. Definition 1. An interface is therefore a description of a set of desired behaviors, with no implementation. 3 Using Interfaces Interface types are used to enhance code reusability. Suppose we have a class called DataSet to find the average and maximum of a set of values (numbers). What if we want to find the average and maximum of a set of BankAccount values, represented by objects of that class? Since our original DataSet class was designed to work with only doubles (numbers), we will have to modify it to work with BankAccount objects: 1
Image of page 1

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

View Full Document Right Arrow Icon
Program 1. public class DataSet // Modified for BankAccount objects { . . . public void add(BankAccount x) { sum = sum + x.getBalance(); if (count == 0 || maximum.getBalance() < x.getBalance()) maximum = x; count++; } public BankAccount getMaximum() { return maximum; } private double sum; private BankAccount maximum; private int count; } Suppose also we have a Coin class and we wanted to find the coin with the highest value among a set of coins. We would need to modify the DataSet class again.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern