c# - Conventions in assignment code? -
I have two classes, knows about A and BBA, and I do not know about A There are properties that can be well set to A, although there is no legacy shared between A and B. Many times when I will need to allocate the assets of A to A, but I am looking for points where I should keep that code.
public class A {} public square b {// constructor? Public B (AA) // // from properties of set B // factory method? Public from stable B (AA) {BB = new B (); // Return B to property of Set B; } // Setter method? Public Static Zero SetBFromA (Bb, AA) {// A to Set B Assets} // Assignment Method? Public Zero AssignFrom (AA) {// property from a set to B}} // Fixed helper class? Public stable class BHelper {Public stable B GetBFromA (AA) {BB = new B (); // Return B to property of Set B; } Public static Zero SetBFromA (BB, AA) {// property from a set B}}
Which one, if any, is one of these common behaviors? Does any of them take the implications on the basis of their signature? For example, using the constructor is generally expressed that B passes the reference to A?
Thank you!
All the options you specify are valid. Whatever you choose depends on the particular circumstances.
// Constructor? Public B (AA) {// property from a set to B}
Constructor patterns can be an option when the data can not exist without data.
// factory method? Public from stable B (AA) {BB = new B (); // Return B to property of Set B; }
The method of the factory will be the method of choice, when the value is B then depends on the prices in A or B. Especially if B is descended, then the value of the value in A will be available.
// Setter method? Public static zero SetBFromA (BB, AA) {// property from a set B}}
The setter method will not apply in your scenario because it will be used when A and B Do not know about each other and need third party intervention.
// Assignment method? Public Zero AssignFrom (AA) {// property of a set B}} This is essentially a visitor's pattern, leaving a travel b and some of its own (graduation days). Thinks about it). This option will be the pattern if data from A to B is optional.
Comments
Post a Comment