0133379426.pdf by Unknown
Author:Unknown
Language: eng
Format: epub
ISBN: 0133379426
Published: 2013-02-27T05:51:36+00:00
12.7 Case Study: Creating and Using Interfaces
473
12.7.5 Modifying Class SalariedEmployee for Use with IPayable
Figure 12.14 contains a modified version of class SalariedEmployee that extends Employee
and implements method GetPaymentAmount. This version of SalariedEmployee is identical
to that of Fig. 12.5 with the exception that the version here implements method GetPay-
mentAmount (lines 35–38) instead of method Earnings. The two methods contain the same
functionality but have different names. Recall that the IPayable version of the method has
a more general name to be applicable to possibly disparate classes. The remaining Employee
derived classes (e.g., HourlyEmployee, CommissionEmployee and BasePlusCommissionEm-
ployee) also must be modified to contain method GetPaymentAmount in place of Earnings
to reflect the fact that Employee now implements IPayable. We leave these modifications
as an exercise and use only SalariedEmployee in our test app in this section.
1
// Fig. 12.14: SalariedEmployee.cs
2
// SalariedEmployee class that extends Employee.
3
using System;
4
5
public class SalariedEmployee : Employee
6
{
7
private decimal weeklySalary;
8
9
// four-parameter constructor
10
public SalariedEmployee( string first, string last, string ssn,
11
decimal salary ) : base( first, last, ssn )
12
{
13
WeeklySalary = salary; // validate salary via property
14
} // end four-parameter SalariedEmployee constructor
15
16
// property that gets and sets salaried employee's salary
17
public decimal WeeklySalary
18
{
19
get
20
{
21
return weeklySalary;
22
} // end get
23
set
24
{
25
if ( value >= 0 ) // validation
26
weeklySalary = value;
27
else
28
throw new ArgumentOutOfRangeException( "WeeklySalary" ,
29
value, "WeeklySalary must be >= 0" );
30
} // end set
31
} // end property WeeklySalary
32
33
// calculate earnings; implement interface IPayable method
34
// that was abstract in base class Employee
35
public override decimal GetPaymentAmount()
36
{
37
return WeeklySalary;
38
} // end method GetPaymentAmount
Fig. 12.14 | SalariedEmployee class that extends Employee. (Part 1 of 2.)
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Adulting by Kelly Williams Brown(3671)
Figure Drawing for Artists by Steve Huston(2799)
Draw Your Day by Samantha Dion Baker(2708)
Drawing Cutting Edge Anatomy by Christopher Hart(2677)
Drawing Shortcuts: Developing Quick Drawing Skills Using Today's Technology by Leggitt Jim(2532)
Make Comics Like the Pros by Greg Pak(2423)
Draw to Win: A Crash Course on How to Lead, Sell, and Innovate With Your Visual Mind by Dan Roam(2277)
How Proust Can Change Your Life by Alain De Botton(2261)
Day by Elie Wiesel(2243)
0041152001443424520 .pdf by Unknown(2220)
How The Mind Works by Steven Pinker(2214)
Rapid Viz: A New Method for the Rapid Visualization of Ideas by Kurt Hanks & Larry Belliston(2195)
Modern Cartooning by Christopher Hart(2188)
Poses for Artists Volume 2 - Standing Poses: An essential reference for figure drawing and the human form. (Inspiring Art and Artists) by Justin Martin(2144)
Draw-A-Saurus by James Silvani(2105)
Learn Drawing Quickly by Sharon Finmark(2089)
Tattoo Art by Doralba Picerno(2083)
Poses for Artists - Dynamic & Sitting: An essential reference for figure drawing and the human form (Inspiring Art and Artists Book 1) by Justin R Martin(2063)
Drawing and Painting Birds by Tim Wootton(2001)