Skip to main content

To transform the Customer-class from a data object, we can ask ourselves the following questions about the data fields:

How do we want to use {data field}? Where is {data field} used? Can and should the use of {data field} be moved to the class?

E.g.:

  • What is the purpose of Customer.Name?

    Possible answers, display the name in a login web page, use the name in mailings to the customer.

    Which leads to methods:

    • Customer.FillInTemplate(…)
    • Customer.IsApplicableForMailing(…)
  • What is the purpose of Customer.DOB?

    Validating the customer's age. Discounts on the customerscustomer's birthday. Mailings.

    • Customer.IsApplicableForProduct()
    • Customer.GetPersonalDiscount()
    • Customer.IsApplicableForMailing()

Given the comments, the example object Customer – both as a data object and as "real" object with its own responsibilities – is too broad; i.e. it has too much properties/responsibilities. Which leads to either lots of components depending on Customer (by reading its properties) or to Customer depending on lots of components. Perhaps there exist different views of customer, perhaps each should have its own distinct class1:

  • The customer in the context of Account and monetary transactions is probably only used to:

    • help humans identify that their money transfer goes to the correct person; and
    • group Accounts.

    This customer does not need fields like DOB, FavouriteColour, Tel, and perhaps not even Address.

  • The customer in the context of a user logging in to a banking website.

    Relevant fields are:

    • FavouriteColour, whcihwhich might come in the form of personalised theming;
    • LanguagePreferences, and
    • GreetingName

    Instead of properties with getters and setters, these might be captured in a single method:

    • PersonaliseWebPage(Template page);
  • The customer in the context of marketing and and personalised mailing.

    Here not relying on the properties of a dataobject, but instead starting from the responsibilities of the object; e.g.:

    • IsCustomerIntrestedInActionIsCustomerInterestedInAction(); and
    • GetPersonalDiscounts().

    The fact that this customer object has a FavouriteColour property, and/or an Address property becomes irrelevant: perhaps the implementation uses these properties; but it might also use some machine learning techniques and use previous interactions with the customer to discover in which products the customer might be interrestedinterested.


1. OfcourseOf course, the `Customer` and `Account` classes wherewere examples, and for a simple example or homework exercise, splitting this cusomercustomer might be overkill, but with the example of splitting, I hope to demonstrate that the method of turning a data object into an object with responsibilities will work.

To transform the Customer-class from a data object we can ask ourselves the following questions about the data fields:

How do we want to use {data field}? Where is {data field} used? Can and should the use of {data field} be moved to the class?

E.g.:

  • What is the purpose of Customer.Name?

    Possible answers, display the name in a login web page, use the name in mailings to the customer.

    Which leads to methods:

    • Customer.FillInTemplate(…)
    • Customer.IsApplicableForMailing(…)
  • What is the purpose of Customer.DOB?

    Validating the customer's age. Discounts on the customers birthday. Mailings.

    • Customer.IsApplicableForProduct()
    • Customer.GetPersonalDiscount()
    • Customer.IsApplicableForMailing()

Given the comments, the example object Customer – both as a data object and as "real" object with its own responsibilities – is too broad; i.e. it has too much properties/responsibilities. Which leads to either lots of components depending on Customer (by reading its properties) or to Customer depending on lots of components. Perhaps there exist different views of customer, perhaps each should have its own distinct class1:

  • The customer in the context of Account and monetary transactions is probably only used to:

    • help humans identify that their money transfer goes to the correct person; and
    • group Accounts.

    This customer does not need fields like DOB, FavouriteColour, Tel, and perhaps not even Address.

  • The customer in the context of a user logging in to a banking website.

    Relevant fields are:

    • FavouriteColour, whcih might come in the form of personalised theming;
    • LanguagePreferences, and
    • GreetingName

    Instead of properties with getters and setters these might be captured in single method:

    • PersonaliseWebPage(Template page);
  • The customer in the context of marketing and and personalised mailing.

    Here not relying on the properties of a dataobject, but instead starting from the responsibilities of the object; e.g.:

    • IsCustomerIntrestedInAction(); and
    • GetPersonalDiscounts().

    The fact that this customer object has a FavouriteColour property, and/or an Address property becomes irrelevant: perhaps the implementation uses these properties; but it might also use some machine learning techniques and use previous interactions with the customer to discover in which products the customer might be interrested.


1. Ofcourse, the `Customer` and `Account` classes where examples and for a simple example or homework exercise splitting this cusomer might be overkill, but with the example of splitting I hope to demonstrate that the method of turning a data object into an object with responsibilities will work.

To transform the Customer-class from a data object, we can ask ourselves the following questions about the data fields:

How do we want to use {data field}? Where is {data field} used? Can and should the use of {data field} be moved to the class?

E.g.:

  • What is the purpose of Customer.Name?

    Possible answers, display the name in a login web page, use the name in mailings to the customer.

    Which leads to methods:

    • Customer.FillInTemplate(…)
    • Customer.IsApplicableForMailing(…)
  • What is the purpose of Customer.DOB?

    Validating the customer's age. Discounts on the customer's birthday. Mailings.

    • Customer.IsApplicableForProduct()
    • Customer.GetPersonalDiscount()
    • Customer.IsApplicableForMailing()

Given the comments, the example object Customer – both as a data object and as "real" object with its own responsibilities – is too broad; i.e. it has too much properties/responsibilities. Which leads to either lots of components depending on Customer (by reading its properties) or to Customer depending on lots of components. Perhaps there exist different views of customer, perhaps each should have its own distinct class1:

  • The customer in the context of Account and monetary transactions is probably only used to:

    • help humans identify that their money transfer goes to the correct person; and
    • group Accounts.

    This customer does not need fields like DOB, FavouriteColour, Tel, and perhaps not even Address.

  • The customer in the context of a user logging in to a banking website.

    Relevant fields are:

    • FavouriteColour, which might come in the form of personalised theming;
    • LanguagePreferences, and
    • GreetingName

    Instead of properties with getters and setters, these might be captured in a single method:

    • PersonaliseWebPage(Template page);
  • The customer in the context of marketing and and personalised mailing.

    Here not relying on the properties of a dataobject, but instead starting from the responsibilities of the object; e.g.:

    • IsCustomerInterestedInAction(); and
    • GetPersonalDiscounts().

    The fact that this customer object has a FavouriteColour property, and/or an Address property becomes irrelevant: perhaps the implementation uses these properties; but it might also use some machine learning techniques and use previous interactions with the customer to discover in which products the customer might be interested.


1. Of course, the `Customer` and `Account` classes were examples, and for a simple example or homework exercise, splitting this customer might be overkill, but with the example of splitting, I hope to demonstrate that the method of turning a data object into an object with responsibilities will work.
Suggested that when splitting the original broad customer, the principle of thinking about responsibilities (i.e. methods) instead of properties remains valid.
Source Link

To transform the Customer-class from a data object we can ask ourselves the following questions about the data fields:

How do we want to use {data field}? Where is {data field} used? Can and should the use of {data field} be moved to the class?

E.g.:

  • What is the purpose of Customer.Name?

    Possible answers, display the name in a login web page, use the name in mailings to the customer.

    Which leads to methods:

    • Customer.FillInTemplate(…)
    • Customer.IsApplicableForMailing(…)
  • What is the purpose of Customer.DOB?

    Validating the customer's age. Discounts on the customers birthday. Mailings.

    • Customer.IsApplicableForProduct()
    • Customer.GetPersonalDiscount()
    • Customer.IsApplicableForMailing()

Given the comments, the example object Customer – both as a data object and as "real" object with its own responsibilities – is too broad; i.e. it has too much properties/responsibilities. Which leads to either lots of components depending on Customer (by reading its properties) or to Customer depending on lots of components. Perhaps there exist different views of customer, perhaps each should have its own distinct class1:

  • The customer in the context of Account and monetary transactions is probably only used to:

    • help humans identify that their money transfer goes to the correct person; and
    • group Accounts.

    This customer does not need fields like DOB, FavouriteColour, Tel, and perhaps not even Address.

  • The customer in the context of a user logging in to a banking website.

    Relevant fields are:

    • FavouriteColour, whcih might come in the form of personalised theming;
    • LanguagePreferences, and
    • GreetingName

    Instead of properties with getters and setters these might be captured in single method:

    • PersonaliseWebPage(Template page);
  • The customer in the context of marketing and and personalised mailing.

    Here not relying on the properties of a dataobject, but instead starting from the responsibilities of the object; e.g.:

    • IsCustomerIntrestedInAction(); and
    • GetPersonalDiscounts().

    The fact that this customer object has a FavouriteColour property, and/or an Address property becomes irrelevant: perhaps the implementation uses these properties; but it might also use some machine learning techniques and use previous interactions with the customer to discover in which products the customer might be interrested.


1. Ofcourse, the `Customer` and `Account` classes where examples and for a simple example or homework exercise splitting this cusomer might be overkill, but with the example of splitting I hope to demonstrate that the method of turning a data object into an object with responsibilities will work.

To transform the Customer-class from a data object we can ask ourselves the following questions about the data fields:

How do we want to use {data field}? Where is {data field} used? Can and should the use of {data field} be moved to the class?

E.g.:

  • What is the purpose of Customer.Name?

    Possible answers, display the name in a login web page, use the name in mailings to the customer.

    Which leads to methods:

    • Customer.FillInTemplate(…)
    • Customer.IsApplicableForMailing(…)
  • What is the purpose of Customer.DOB?

    Validating the customer's age. Discounts on the customers birthday. Mailings.

    • Customer.IsApplicableForProduct()
    • Customer.GetPersonalDiscount()
    • Customer.IsApplicableForMailing()

To transform the Customer-class from a data object we can ask ourselves the following questions about the data fields:

How do we want to use {data field}? Where is {data field} used? Can and should the use of {data field} be moved to the class?

E.g.:

  • What is the purpose of Customer.Name?

    Possible answers, display the name in a login web page, use the name in mailings to the customer.

    Which leads to methods:

    • Customer.FillInTemplate(…)
    • Customer.IsApplicableForMailing(…)
  • What is the purpose of Customer.DOB?

    Validating the customer's age. Discounts on the customers birthday. Mailings.

    • Customer.IsApplicableForProduct()
    • Customer.GetPersonalDiscount()
    • Customer.IsApplicableForMailing()

Given the comments, the example object Customer – both as a data object and as "real" object with its own responsibilities – is too broad; i.e. it has too much properties/responsibilities. Which leads to either lots of components depending on Customer (by reading its properties) or to Customer depending on lots of components. Perhaps there exist different views of customer, perhaps each should have its own distinct class1:

  • The customer in the context of Account and monetary transactions is probably only used to:

    • help humans identify that their money transfer goes to the correct person; and
    • group Accounts.

    This customer does not need fields like DOB, FavouriteColour, Tel, and perhaps not even Address.

  • The customer in the context of a user logging in to a banking website.

    Relevant fields are:

    • FavouriteColour, whcih might come in the form of personalised theming;
    • LanguagePreferences, and
    • GreetingName

    Instead of properties with getters and setters these might be captured in single method:

    • PersonaliseWebPage(Template page);
  • The customer in the context of marketing and and personalised mailing.

    Here not relying on the properties of a dataobject, but instead starting from the responsibilities of the object; e.g.:

    • IsCustomerIntrestedInAction(); and
    • GetPersonalDiscounts().

    The fact that this customer object has a FavouriteColour property, and/or an Address property becomes irrelevant: perhaps the implementation uses these properties; but it might also use some machine learning techniques and use previous interactions with the customer to discover in which products the customer might be interrested.


1. Ofcourse, the `Customer` and `Account` classes where examples and for a simple example or homework exercise splitting this cusomer might be overkill, but with the example of splitting I hope to demonstrate that the method of turning a data object into an object with responsibilities will work.
Source Link

To transform the Customer-class from a data object we can ask ourselves the following questions about the data fields:

How do we want to use {data field}? Where is {data field} used? Can and should the use of {data field} be moved to the class?

E.g.:

  • What is the purpose of Customer.Name?

    Possible answers, display the name in a login web page, use the name in mailings to the customer.

    Which leads to methods:

    • Customer.FillInTemplate(…)
    • Customer.IsApplicableForMailing(…)
  • What is the purpose of Customer.DOB?

    Validating the customer's age. Discounts on the customers birthday. Mailings.

    • Customer.IsApplicableForProduct()
    • Customer.GetPersonalDiscount()
    • Customer.IsApplicableForMailing()