class design question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hey all,
i have an employee class that's part of an employee management system. If I
want to expose the employee's Leave time details (or any details of the
employee that's one-to-many) would I expose that as a property or a method?
Or does it matter?

thanks,
rodchar
 
hey all,
i have an employee class that's part of an employee management system. If I
want to expose the employee's Leave time details (or any details of the
employee that's one-to-many) would I expose that as a property or a method?
Or does it matter?

thanks,
rodchar

If the value is calculated, and doing so will trigger a series of
operations, or if doing so may take time, definitely implement it as a
method. Some examples might include querying a database, iterating
over a collection, or returning a clone of another object.

If the value is something that you want to be able to get or set,
implement it as a property. Also, if the value you want to return is
initialized during object construction, and likely isn't going to
change frequently over the lifetime of the object, a read-only
property might be suitable, especially if it's calculated before the
object is constructed.

When is the value calculated? Is it passed into the constructor?
 
Thank you for the generous help.

Mike Hofer said:
If the value is calculated, and doing so will trigger a series of
operations, or if doing so may take time, definitely implement it as a
method. Some examples might include querying a database, iterating
over a collection, or returning a clone of another object.

If the value is something that you want to be able to get or set,
implement it as a property. Also, if the value you want to return is
initialized during object construction, and likely isn't going to
change frequently over the lifetime of the object, a read-only
property might be suitable, especially if it's calculated before the
object is constructed.

When is the value calculated? Is it passed into the constructor?
 
you don't need to do either.


you need to build a DATABASE and assigne permissions to the columns

OOP is a waste of time, kid
 
Back
Top