1

I'm working on a small scale API project but as it will be used and maintained by people that are not Software Engineers to trade I am attempting to keep the design as separate and identifiable as possible, using SOLID has made this easier.

But a few of my objects require to change (say made "active") which then in turn should make the other object that was "active" now disabled. This is simply a property of the object. This requires me to still know about all the objects even after they have been returned to the user.

So I've thought up that I can use an "Object Store" which will store the object's created before they are actually returned to the user of the system, but I'm unsure where in my pattern of creating objects that this sits. I've added an image below that shows how the objects are created within my solution.

Creating objects pattern

So within my solution the controller get's the necessary properties to build an object (this may include interfacing externally but I've missed this out my diagram). This passes the arguments to the factory that then actually builds the object.

So I was thinking of adding to my "object store" in the controller after it has requested the factory to build the object, but the issue with this is that it then means that the controller will be responsible for, getting the necessary arguments and storing the created objects.

I was also thinking that it could be placed between the controller and the factory so that the controller said "GetObject" on the "object store" and this could save it internally but this then means that the object store won't just store objects it will also request for them to be built.

Is there any pointers on where this could sit and why? Perhaps my pattern for creating objects is incorrect (seems to have been OK up to now)?

Specifics so what I am doing is an adapter that sits over the ActiveX interface of Third-party software that my Company uses. This will be used as an API by other "engineers" within the company for automating tasks that the third party software does. As object "X" in my example returns a collection of "Y"'s I am looking for a method of changing a property on the other Y's when one changes, like a "active" flag, one is made active the current active is dis-activated. I don't know how much more specific I can be without saying exactly what the application is or does.

  • Could you give some specifics of what you are actually doing? It is hard to grasp this when it is purely theoretical. – user82096 Oct 1 '15 at 8:23
  • @dan1111 Specifics wise I am developing an adapter that sits on top of an ActiveX interface for a Third-Party piece of software that we use, my adapter will be used as an a method of making the ActiveX interface more user friendly. The part I'm trying to do just now is be able to set object properties that have been returned to the user without having to have a top level manager class that the user interfaces with. – Stephen Ross Oct 1 '15 at 8:33
  • I second @dan1111 's point. but it seems like you have too many Managers, Controllers and factories to me – Ewan Oct 1 '15 at 8:48
  • Ok I have added a little more to the question that specifies my question, but unfortunately the overall nature doesn't allow me to go into great detail. I had thought that I had too many Controllers and Factories but I'm attempting to make sure everything has a single responsibility, which I believe they do? – Stephen Ross Oct 1 '15 at 9:09
  • You could say what the X is called and does. ie. CCPaymentAPI.GetCards() returns a list of cards, one of which is 'active' and why just maintaining a list of references and changing the property on them all when the active card changes wont work – Ewan Oct 1 '15 at 9:22
1

In Cases where you have a property on an object which is dependent on other objects in a group. It can sometimes be a good idea to move this to be a property of the group, rather than a property of each object.

eg

say we have an eCommerce system where customer have accounts with multiple credit cards. However only one one credit card is active at a time.

instead of:

CreditCard.IsActive

We could instead have

Account.ActiveCardId

This will enforce the 'only one at a time' nature of Active and allow you to use each CreditCard as an invariant data object.

| improve this answer | |
  • Although this wasn't what I was expecting as an answer to begin with it helped me see that the overall design of the objects was incorrect and rather than attempt to work my design around this adding complexity this will simplify this area a lot. As I won't need to know about the collection of objects created only the "Active" one which can be switched around easier. – Stephen Ross Oct 1 '15 at 11:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.