Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I am new to object oriented development and appreciate your help in this regard. In my payroll system, I have four classes called ‘Payment’, ‘Salary’, ‘Earning’ and ‘Deduction’. preparing salary requires many types of earnings (like OT, Incentives, Spacial Allowance, payments for extra shifts, budgetary allowances, Brought forward amounts etc.) and deductions (like Insurance, Uniform, Loans,Recovery, Welfare, meals, salary advance taken etc.) So I split this in to two classes namely 'Earning' and 'Deduction'. Finally class 'Salary' is supposed to do the balancing part and class 'payment' will handle payment part (banking). Other type of payment is salary advance which is just an amount paid monthly. the relationships modeled, as follows… ‘Earning’ and ‘Deduction’ classes has a composition relationship with ‘Salary’ and ‘Salary’ is a derived class from ‘Payment’. I have implemented these relationships in my C# code as follows… My questions are

1.Whether I ve related classes in a proper way?

2.Is implementation of the relationships correct?

PAYMENTS

C#
class payment
    {
        public virtual void pay()
        {

        }
}


SALARY

C#
class salary:payment
{
//Composition of ‘Earning’ class
    private earning E1;

    public salary()
    {
        E1 = new earning(this);

    }
//Calling calEarning() of ‘Earning’ class through ‘Salary’ class
    public void calEarningForSal()
    {
        E1.calEarning();
    }

//Implementing pay method of base class 
    public override void pay()
    {

    }
}


EARNING

C#
public class earning
   {
   //Since earning has a composition relationship with salary…
       private salary S1;

       internal earning(salary sal)
       {
           this.S1 = sal;
       }
   //This method will calculate earnings of employees
       public void calEarning()
       {

       }
   }


MAIN METHOD

C#
Main()
        {
            salary newSal = new salary();
            newSal.calEarningForSal();
        }
Posted

1 solution

Well one thing I want to add here.
You can create a parent class Head or salaryhead.
Class SalaryHead { }
Class Earning:SalaryHead{}
Class Deduction : SalaryHead {}
Main { we can use abstract factory to create objects at run time}

But in payroll system this is not all, I think we need more classes and inheritance to design a payroll system. Like one important class is employee and it should be related with payroll classes.
 
Share this answer
 
Comments
girishmeena 6-Apr-14 1:28am    
Can you eaxplain me downvoting my answer. Just downvoting doesn't work you need to give proper explanations why you are downvoting it. Please

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900