Hi guys,
I'm designing several classes that interact with each other, and I'm doing my best to make sure that these classes are weakly couples wherever possible. This has led me to implement the following design:
I'm constructing a web crawler that consists of several main classes/interfaces:
*Crawler
*CrawlerStrategy
*PageSorter
These three classes do the majority of the work. I also have several classes/interfaces designed mostly to carry data:
*CrawlerPage
*CrawlerLink
These data-encapsulating classes will be instantiated primarily by CrawlerStrategy implementations (as it's responsibility is providing an executing a method for crawling the site). To support weak coupling, The CrawlerStrategy class should instantiate instances of CrawlerLink and CrawlerPage through a factory of some kind, correct? But if so, how should I support weak coupling between the CrawlerStrategy class and the Factory class? I've come up with several ideas:
1. Store a reference to the factory internally for every class that requires it's use - this seems like a poor idea, and a lot of useless coding to get and set the factory.
2. Use a singleton manager of some kind to reference the factory object - Better than the first idea, but that still requires strong coupling between the singlton manager and the classes instantiating the objects, which just seems like i'm moving the dependancy elsewhere in the code.
Any ideas? I'd be happy to clarify anything I can if part of this isn't clear. Thanks in advance!
-Sean
I'm designing several classes that interact with each other, and I'm doing my best to make sure that these classes are weakly couples wherever possible. This has led me to implement the following design:
I'm constructing a web crawler that consists of several main classes/interfaces:
*Crawler
*CrawlerStrategy
*PageSorter
These three classes do the majority of the work. I also have several classes/interfaces designed mostly to carry data:
*CrawlerPage
*CrawlerLink
These data-encapsulating classes will be instantiated primarily by CrawlerStrategy implementations (as it's responsibility is providing an executing a method for crawling the site). To support weak coupling, The CrawlerStrategy class should instantiate instances of CrawlerLink and CrawlerPage through a factory of some kind, correct? But if so, how should I support weak coupling between the CrawlerStrategy class and the Factory class? I've come up with several ideas:
1. Store a reference to the factory internally for every class that requires it's use - this seems like a poor idea, and a lot of useless coding to get and set the factory.
2. Use a singleton manager of some kind to reference the factory object - Better than the first idea, but that still requires strong coupling between the singlton manager and the classes instantiating the objects, which just seems like i'm moving the dependancy elsewhere in the code.
Any ideas? I'd be happy to clarify anything I can if part of this isn't clear. Thanks in advance!
-Sean