Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 707547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:17:24+00:00 2026-05-14T04:17:24+00:00

I am confuse between the best way to organize dependency between multiple classes assume

  • 0

I am confuse between the best way to organize dependency between multiple classes
assume i have the following classes
Employee,
Salary,
DataAccess

Should i go for:
Option1

Employee emp = new Employee();
Salary sal = new Salary();
DataAccess data = new DataAccess();

sal.Calculate(emp);
data.Save(emp);

or Option2

Employee emp = new Employee();
Salary sal = new Salary();

sal.Calculate(emp); //once salary has been calculated salary object will initialize  data access class to do the actual saving.

or Option 3

Employee emp = new Employee();
emp.Calculate(); // employee object will encapsulate both the salary and data access object
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T04:17:24+00:00Added an answer on May 14, 2026 at 4:17 am

    Usually Employee HAS-A salary. So I’d go with something like:

    Employee emp = new Employee();
    emp.Salary = new Salary();
    

    You can create a generic class that would fetch all of the salary calculation business rules in it(from a data source), and calculate salary for employees based upon employee attributes.

    SalaryCalculator.CalculateSalary(emp); //I'd agree with Silky
    DataAccess.Save(emp); //This shall save changes in emp as well as in salary.
    

    –EDIT–

    This is in response to your comment.

    Your hrms object(if any) should then encapsulate the Employee, and provide a CalculateSalary option.

    How about something like:

    yourHrms.Employees.Add(new Employee(Age, Name, DateOfBirth, EmployedSince, TotalExperience, IsManager, new Salary(someStartPointForSalaryIfAny));
    

    Here your Salary class would inherit from your abstact BaseSalary class, that would contain the business rules, and would perform the Calculate()ions. Therefore, the new Salary(someStartPointForSalaryIfAny) would perform the calculation internally.

    To save your object you can have:

    yourHrms.Employees.Save();//Saves all employees.
    yourHrms.Employees[0].Save();//Save this.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.