views:

96

answers:

1
+1  A: 

The problem as I understand it:

As of now, your AddFileHelper only adds files to your project resource labeled ''resource1'' which is a problem because every time a filetype “A” is passed your AddFileHelper, you to make a new resource for your project (''resource2'') and add it to that.

There is a very simple way to do this. Within AddFileHelper test the FileType of the added file and determine whether or not you need a new resource to be added to your project. If the type isn't “A” you'll call the code that you have now and add the file with:

res.AddFile(path, type, id);

If the type to add is “A” and you need a new resource, just redefine res and increment a counter variable of how many resources you have in your project:

Resource res = p.CreateProjectResource(resourceName);
resourceCounter++;

Where resourceName is the string:

string resourceName = ''resource'' + resourceCounter;

All this should be implemented as your AddFileHelper method.

Regarding the overall structure of your code, the AddFileHelper should be a project class method. Here's why:

The AddFile method, and the AddFileHelper method sound similar but do two very different things. The AddFile method belongs to the resource class because it acts on a well defined resource object. However, the AddFile method is not enough for your purposes because the resource file to append to is not immediately apparent to the client who has a file and wants to add it to your project. Bbefore the AddFile method can be called, the target resource needs to be determined. The job of the AddFileHelper method is to determine which resource will call the AddFile method. Therefore, the AddFileHelper method belongs to the project class and the AddFile method to the resource class.

The logical connection between the AddFileHelper method and the project class might be more apparent if you renamed the method to FileResourceAssignment or something like that.

Ami
where to implement the AddFileHelper..within "Project" class or outside?
Amitd
I think AddFileHelper should be a Project class method. The alternative would be to make a FileFactory class (http://en.wikipedia.org/wiki/Factory_design_pattern) and have the Project class implement an AddFile method but that doesn't seem to be necessary in your case.
Ami
I was thinking of the same but thing is File belongs to a Resource more than to a Project. So wouldn't resource.AddFile(file) be more logically correct than Project.AddFileHelper(file) ?? this is the part which confuses me....
Amitd
I have edited my answer to address this question.
Ami