tags:

views:

26

answers:

1

i wonder where one can find template interfaces.

eg. i am creating these classes that implements iLog:

 DatabaseLog
 ScreenLog
 FileLog

i wonder what methods should a typical Log class have?

is there a set of interfaces you could just implement/learn from rather than reinvent the wheel and have to think about the method names.

eg. Interfaces:

 iLog
 iDatabase
 iErrorMessage
 etc.

Thanks

+1  A: 

PHP defines the following interfaces (should, but may not be complete):

  • Traversable — The Traversable interface
  • Iterator — The Iterator interface
  • IteratorAggregate — The IteratorAggregate interface
  • ArrayAccess — The ArrayAccess interface
  • Serializable — The Serializable interface
  • Countable — The Countable interface
  • OuterIterator — The OuterIterator interface
  • RecursiveIterator — The RecursiveIterator interface
  • SeekableIterator — The SeekableIterator interface
  • SplObserver — The SplObserver interface
  • SplSubject — The SplSubject interface

See

As for your Logger Interface, I'd say it should have a method log($message, level) and nothing else.

Gordon
thanks for the links! regarding the logger interface. shouldnt there be a method called read() ? or is it another interface that is responsible for reading?
never_had_a_name
@fayer depends on the what your Log is supposed to do. I was assuming you are talking about a LogWriter. If your Log can read and write, why not separate these concerns into two interfaces and then have your Logger implement LogWriter and LogReader and give one a method write() and the other a method read().
Gordon
that was actually a nice separation. i will think about wether to separate them or having them in one interface, although it sounds like each logger should have the ability to read too.
never_had_a_name
@fayer a common approach is to have the Logger be a composite that aggregates multiple Writers, so you can write to (for instance) file and db at the same time. The Logger class is then just a Gateway. You could add reading, but the Logger Gateway would then have to know from which Reader, which I find less useful, because it makes you having to know what Reader is there.
Gordon