Let's say I have a class Customer, which has a property customerType.
I have another class called something like SpecialContract, which has a Customer and some other properties.
If customer.customerType == SPECIAL, then there is a SpecialContract which has a reference to this particular Customer.
Now I realize that this is a bit hoaky, but I do not want to maintain a relationship from Customer to SpecialContract for a few reasons, one being that most of the time when working with Customers we don't need to load up SpecialContracts and all of the other data associated with SpecialContracts. However, I do always want to know if a Customer has a SpecialContract, and this is achieved through its customerType property.
Ok, here's the hard part. I don't want the client to be able to set customerType, because just doing so will not remove the SpecialContract that applies to the Customer, which would be required. I would rather force the client to call a service method to remove the SpecialContract, which would also set the customerType to NOTSPECIAL all in one transaction.
How can I hide the customerType setter from clients, but still expose it to my service layer class that will be responsible for setting the correct value and also removing the SpecialContract? My service class is not in the same package as the Customer class.