Anyway, one thing I'm having a little difficulty with is the way the book is presenting the Law of Demeter. That is, I think I understand, but I want to know I understand. If I'm correct, they way I'm implementing this is 'correct.' If I'm not, then I'm misunderstanding.
Rather than giving you chunks of code with what I've written I'll give a basic description - and if more information will help by all means I'll provide it. Maybe I'm confusing two parts of the chapter, even.
So the Law of Demeter, as presented by the book, states that "a module should not know the innards of the objects it manipulates." It goes on to clarify that:
Robert C. Martin, Clean Code, Page 97-98 said:
- An object created by ƒ
- An object passed as an argument to ƒ
- An object held in an instance variable of C
The method should not invoke methods on objects that are returned by any of the allowed functions.
This is in the context of discussing Data Structures as opposed to Objects. I have a data structure, and an object I'm using that handles the data from the data structure, once the data is created.
I have two classes: TemplateData and TemplateMailer
TemplateData consists of a number of private variables, with setters/getters.
name,path,preSubject,postSubject are all set by function SetDBValues(name, tier) which does a DB query to get the data based on the name of the template needed and the customer's service tier.
the rest of the variables (about 15) use setters/getters.
The TemplateMailer is fairly simple. It has two functions. BuildTemplate(templateData) and Send(). It creates a mail item(The mail item is a class variable so once it's created it's held by the mailer. ), loads the HTML from the template into the mailitem, and then replaces strings in the template with information from the TemplateData. Actually, this would probably make more sense if I showed that function.
Set outlookApplication = New Outlook.Application Set outlookItem = oApplication.CreateItemFromTemplate(data.GetPath) With outlookItem 'XXXXX ticket is a field dynamically added to each template. As such we need 'to do some quick logic to make sure it exists before we add it. So do XXXXX first. If Not data.GetXXXXX = "" Then .HTMLBody = Replace(.HTMLBody, "INSERT_XXXXX_LABEL", "XXXXX Ticket#:") Else .HTMLBody = Replace(.HTMLBody, "INSERT_XXXXX_LABEL", "") .HTMLBody = Replace(.HTMLBody, "INSERT_XXXXX_TICKET", data.GetXXXXX) 'set date/times .HTMLBody = Replace(.HTMLBody, "INSERT_INCIDENT_START_DATE_TIME", Format(data.GetStartTime, "mm/dd/yyyy h:mm AMPM") & " EST") .HTMLBody = Replace(.HTMLBody, "INSERT_INCIDENT_END_DATE_TIME", Format(data.GetEndTime, "mm/dd/yyyy h:mm AMPM") & " EST") .HTMLBody = Replace(.HTMLBody, "INSERT_UPDATE_DATE_TIME", Format(data.GetNextUpdate, "mm/dd/yyyy h:mm AMPM") & " EST") 'set ticket data .HTMLBody = Replace(.HTMLBody, "INSERT_REMEDY_TICKET", data.GetRemedy) .HTMLBody = Replace(.HTMLBody, "INSERT_XXXXX_TICKET", data.GetXXXXX) .HTMLBody = Replace(.HTMLBody, "INSERT_PRIORITY", data.GetPriority) 'set verbiage .HTMLBody = Replace(.HTMLBody, "INSERT_INCIDENT_DESCRIPTION", data.GetShortDescription) .HTMLBody = Replace(.HTMLBody, "INSERT_SITUATION", data.GetSituation) .HTMLBody = Replace(.HTMLBody, "INSERT_IMPACT", data.GetImpact) .HTMLBody = Replace(.HTMLBody, "INSERT_FIX", data.GetFix) .HTMLBody = Replace(.HTMLBody, "INSERT_ASSESSMENT_IMPACT", data.GetAssessment) 'Signature and Subject .HTMLBody = Replace(.HTMLBody, "INSERT_XXXXX_SIGNATURE", DLookup("strEmpName", "tblCurrentXXXXX")) .subject = data.GetPreSub & " " & data.GetShortDescription & data.GetPostSub .BCC = .BCC & "; " & data.GetBCC .CC = data.GetCC End With End Function
So I'm trying to determine: have I successfully separated the data from the object, or is there a better way I should go about this? Does my Mailer know too much about my Data? If I'm understanding the book correctly, then I think I'm doing this right. If not, I would love some clarification.
Better yet, is this a complete mess entirely? I'd love suggestions, corrections, critiques - I want to be a good programmer some day, with pretty and professional looking code. Since the above is already in production it's not likely to be changed any time soon, but I'd still like to be able to do better moving forward.
I truly hope this has made sense.
(aside, the XXXXX in the code section is a client name that had to be chopped out)
This post has been edited by depricated: 01 November 2012 - 11:22 AM