Sha256: c68ba203d5c631cc3228fcc323335d15b7140455a09c91ee24375908f53e89b3
Contents?: true
Size: 1.09 KB
Versions: 4
Compression:
Stored size: 1.09 KB
Contents
A conventional architecture will have each component instantiate its own dependencies. For example, the @Application@ would do something like this: <pre> class Application def initialize @logger = Logger.new @authenticator = Authenticator.new @database = Database.new @view = View.new @session = Session.new end end </pre> However, the above is already flawed, because the @Authenticator@ and the @Session@ both need access to the @Database@, so you really need to make sure you instantiate things in the right order and pass them as parameters to the constructor of each object that needs them, like so: <pre> class Application def initialize @view = View.new @logger = Logger.new @database = Database.new( @logger ) @authenticator = Authenticator.new( @logger, @database ) @session = Session.new( @logger, @database ) end end </pre> The problem with this is that if you later decide that @View@ needs to access the database, you need to rearrange the order of how things are instantiated in the @Application@ constructor.
Version data entries
4 entries across 4 versions & 1 rubygems