Recommended way of dealing with a class with hundred of attributes

I have a Client class that contains many attributes(about 100).In my html form however, I grouped these details into Personal, Medical, Employer, Payment, Beneficiaries etc.
When I designed the class, the constructor of the class was cluttered with all those variables. I thought of creating separate classes for the Personal, Medical, Employer, Payment and Beneficiaries details, just to reduce the number of fields in the main class.

class Client

	protected Personal $personal;
	protected Medical $medical;
	protected Employer $employer;
	protected Payment $payment;
	protected Beneficiary $beneficiary;

	protected $db;

	function __construct($personal, $medical, $employer, $payment, $beneficiary, DB $db)
		$this->personal = $personal;
		$this->medical = $medical;
		$this->employer = $employer;
		$this->payment = $payment;
		$this->beneficiary = $beneficiary;

		$this->db = $db->getConnection();


	public function register()


Is this the proper way to go? If it is ok, then how do I efficiently extract all the other information and save to their corresponding tables.

you should look into the Entity-Attribute-Value data model. it may make a lot more sense with your data.

That’s usually an indication for a design problem …

And as a side note, the database connection does not have anything to do in a user class.

Thanks for replying, I know it is a design problem, that is why I needed a help.

have a look at the E-A-V data model.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.