csc2700lect01

Csc2700lect01 - CSc 2700 Lecture 0& 1 Interfaces August 26& 28 2008 1 Administrative Matters Discussion on class policies syllabus Netbeans

Info iconThis preview shows pages 1–3. 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
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 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 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....
View Full Document

This note was uploaded on 10/06/2009 for the course CSC 2700 taught by Professor Duncan during the Spring '08 term at LSU.

Page1 / 6

Csc2700lect01 - CSc 2700 Lecture 0& 1 Interfaces August 26& 28 2008 1 Administrative Matters Discussion on class policies syllabus Netbeans

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

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