Globallogic services often pass employee profiles between components that may update address records independently. Design a mutable Address class and an immutable Employee class that prevents external mutation of employee identity and stored address state.
Address must store street and city, and allow both fields to be changed after construction.Employee must store employee_id, name, and an Address.Employee must not allow reassignment of employee_id, name, or its internal address reference.Address, so later changes to the caller's address do not affect the employee.employee.address must return another defensive copy, so callers cannot mutate the employee through the returned object.create_employee(employee_id, name, address_data), which constructs an employee from an address dictionary and returns its dictionary snapshot using to_dict().Input consists of an integer employee_id, a string name, and a dictionary containing string keys street and city. The helper returns a dictionary with keys employee_id, name, street, and city. The classes must enforce the immutability and defensive-copying rules above.
def create_employee(employee_id, name, address_data):