PHP class: too many properties bad?
I have a class that has a lot properties
. The first part of the question, as stated above, is it bad to have too many bad properties
classes? If so, what steps should be taken to improve the code and code performance?
For example, I have a Person class:
class FamilyMember extends Base
{
public
$stateId, $familyId, $memberId,
$firstName, $middleName ,$lastName, $dob, $birthPlace, $father, $mother, $maritalStatus, $spouse,
$gender, $religion, $caste, $education, $trainings ,$disabilityStatus,
$stayLocation, $employment, $annualIncome, $mobileAccess, $internetAccess;
}
Does it help me make them private/protected
?
Next part of the question: In real applications, how do people deal with this? Is it ideal to have such a cluster?
source to share
Since it Base
appears to be following something similar to a pattern ActiveRecord
(i.e. matching database table rows to a PHP object), this is not uncommon. You can use templates protected
or private
and getter
/ setter
to make your code a little more promising. for example for line versioning.
source to share