Get Weather - Step 8 - Adding Abstraction. Pt 2.


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. //creating the so called "abstraction" layer...(!!!!)
  2. abstract class BaseCache{
  3.  
  4. public function BaseCache(){
  5. //some intitialization here...
  6. }
  7.  
  8. abstract public function set($key, $val);
  9.  
  10. abstract public function get($key);
  11.  
  12. }
  13.  
  14.  
  15. //no "abstract" key word before class
  16. //and before abstract methods (unless...MemCahce was abstract itself...)
  17. class MemCache extends BaseCache{
  18.  
  19. public function set($key, $val){
  20. //...
  21. }
  22.  
  23.  
  24. }
  25.  
  26.  
  27. class DBCache extends BaseCache{
  28.  
  29. public function set($key, $val){
  30. // " INSERT INTO my_cache_table (key, val) values ("$key", "$val")..."
  31. }
  32.  
  33. public function get($key) {
  34. // SELECT key,val from my_cache_table where key=$key..."
  35. }
  36. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.