1 Replies - 195 Views - Last Post: 08 June 2012 - 03:36 AM Rate Topic: -----

#1 immeraufdemhund  Icon User is offline

  • D.I.C Regular

Reputation: 79
  • View blog
  • Posts: 495
  • Joined: 29-March 10

Idea for base classes and implementation

Posted 07 June 2012 - 01:07 PM

I'm needing to bounce my ideas around and get them out of my mind. I'm making a Zoho Api tool in C#. Right now it is going to be limited in use in that I only care about posting potentials to Zoho. I have seen though that some people on the Zoho website asking for .net support so they can easily post to Zoho. So since I have to make one for my self for work I figured I could help the community and my self by making a .net dll.

I've got a fair amount of work done so far as I am able to post to my test account at zoho. I have a ZohoXml class, and a ZohoBaseFieldClass (which i named poorly as ZohoBaseModule, i'll rename that) it is an interface with one bool method called IsSendable(). ZohoPotentials implements that base field class. At first I decided to just make a property for each of the properties that Zoho has available. But that doesn't allow for custom Fields that you can put into Zoho. Also if a end user decides that they want a particular field required (even though zoho doesn't require it) then I would be up a creek.

So here is my idea. What if i make a base property class for my zoho fields? I'm thinking that I could actually kill two birds with one stone with this. With this base class if I make 2 bool properties called Required and HasValue then I could get rid of my base field interface.

Also I have to have a way to pass the Field Name to the ZohoXml. Well if my zoho Properties had 2 string properties called Key and Field Name (or value) then in my ZohoXml I could just have a Constructor with a ZohoBaseClass (guess I do need that) and have it iterate through my ZohoProperties and check if it is required and format it correctly in the proper nodes.

But is this too convoluted? is this too unclean? I'm thinking that in this case I would have less dependancies and be able to decouple my classes a bit better and it would allow for easier testing since I'm doing TDD. but I wanted to get a little feedback before i decided to change all my classes (thankfully I only have 1 FieldClass).. This is what my ZohoPotentials class looks like now.

using System;
/*
 * User: Ert
 * Date: 5/7/2012
 * Time: 8:14 PM 
 */

namespace ZohoApi
{
    public class ZohoPotentials : ZohoBaseModule
	{
		public string PotentialOwner { get; set; }
		public string PotentialName { get; set; }
		public string AccountName { get; set; }
		public string PotentialType {get; set;}
		public string LeadSource { get; set; }
		public string CampaignSource { get; set; }
		public string ContactName { get; set; }
		public decimal Amount { get; set; }
		public DateTime ClosingDate { get; set; }
		public string NextStep { get; set; }
		public string PotentialStage { get; set; }
		public int Probability { get; set; }
		public decimal ExpectedRevenue { get; set; }
		public string CreatedBy { get; set; }
		public string ModifiedBy { get; set; }
		public string Description { get; set; }
		
		public ZohoPotentials(string potentialName, string accountName, DateTime closingDate, string potentialStage)
		{
			this.PotentialName = potentialName;
			this.AccountName = accountName;
			this.ClosingDate = closingDate;
			this.PotentialStage = potentialStage;
		}
		
		public bool IsSendable()
		{
			bool HasPotentialName = !string.IsNullOrEmpty(PotentialName);
			bool HasAccountName = !string.IsNullOrEmpty(AccountName);
			bool HasClosingDate = ClosingDate != null;
			bool HasStage = !string.IsNullOrEmpty(PotentialStage);
			
			return HasPotentialName && HasAccountName && HasClosingDate && HasStage;
		}
	}
}



So i'm thinking that I would change that to somethign more like

using System;
/*
 * User: Ert
 * Date: 5/7/2012
 * Time: 8:14 PM 
 */

namespace ZohoApi
{
    public class ZohoPotentials : ZohoBaseModule
	{
        public List<ZohoProperties> theProps {get; set;}		
		public ZohoPotentials(string potentialName, string accountName, DateTime closingDate, string potentialStage)
		{
            this.theProps.Add("Potential Name", potentialName, true)//true means require
            this.theProps.Add("Account Name", accountName, true)//true means require
            this.theProps.Add("Closing Date", closingDate, true)//true means require
            this.theProps.Add("Stage", potentialStage, true)//true means require
		}
		
	}
}



Looking at it now I would think i would have to make my own collection too so I could use that add method. That would be good, because then I could have a is sendable in that collection! yeah. I think i might do this unless you smart people think it would be dumb and a waste of time.

Is This A Good Question/Topic? 1
  • +

Replies To: Idea for base classes and implementation

#2 JackOfAllTrades  Icon User is online

  • Saucy!
  • member icon

Reputation: 5671
  • View blog
  • Posts: 22,519
  • Joined: 23-August 08

Re: Idea for base classes and implementation

Posted 08 June 2012 - 03:36 AM

Your latter code looks like the Entity-Attribute-Value Antipattern, and I would therefore recommend avoiding it.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1