CodingDesign Patterns

 

Press Ctrl+Enter to quickly submit your post
Quick Reply  
 
 
  
 From:  Mikee   
 To:  Mikee      
34068.2 In reply to 34068.1 

Hmm.. possibly something like this:

php code:
 
 
class Outputter {
 $sources = array();
 public function RegisterDataSource($datasource){
  if ($datasource typeof IDataSource){
   $sources[] = $datasource;
  }
 }
 public function PullData (){
  for (var $i=0; $i<sizeof($sources); $i++){
   $sources[i].PushData($this);
  }
 }
}
 
<p>interface IDataSource {
 PushData($outputter);
}
 
SessionManager implements IDataSource
{
  function PushData($outputter){
   $outputter.WriteElement(&quot;blah&quot;,$this-&gt;property); 
   $outputter.WriteCDataElement(&quot;blah&quot;,$this-&gt;anotherproperty);
 }
}
 
 
PlayerController implements IDataSource
{
  function PushData($outputter){
   $outputter.WriteElement(&quot;blah&quot;,$this-&gt;property); 
   $outputter.WriteCDataElement(&quot;blah&quot;,$this-&gt;anotherproperty);
 }
}
 
Authenticator implements IDataSource
{
  function PushData($outputter){
   $outputter.WriteElement(&quot;blah&quot;,$this-&gt;property);
   $outputter.WriteCDataElement(&quot;blah&quot;,$this-&gt;anotherproperty);
 }
}

..etc..




[Mwah]
0/0
 Reply   Quote More 

 From:  THERE IS NO GOD BUT (RENDLE)  
 To:  Mikee      
34068.3 In reply to 34068.1 
In purist terms, you should have a common data class which is exported from the service classes and can be formatted by the Output classes. That way you can add new Outputters or a new service without needing to modify existing code, as long as they use this common intermediate class. Check out loose coupling for more info.

Adjunct: the application I'm working on lets users manipulate the business object graphs themselves for export, custom wizard building, etc. Sometimes the graph is presented in a tree-view, and sometimes in cascading popup menus. But both ways are essentially a tree with nodes, some of which have child nodes. So I'm going to write wrapper classes around TreeView, TreeNode, PopupMenu and MenuItem, which implement common interfaces so I can write a single class to populate both without mucking about. Then when I add a WPF-based UI, I can simply write another wrapper and all the existing code will Just Work™.

Singletons are generally bad, btw. There's a difference between only needing one instance of a class, and needing only one instance of a class.

Dance like it hurts; Love like you need the money; Work when people are watching.
0/0
 Reply   Quote More 

 From:  Mikee   
 To:  THERE IS NO GOD BUT (RENDLE)     
34068.4 In reply to 34068.3 

My brain is starting to hurt more.

 

"There's a difference between only needing one instance of a class, and needing only one instance of a class."

 


Gah.

 


The more I think about what it is I need to do, the more I'm losing concentration and the TV keeps seeming more and more interesting.

 

I'm starting to question my origional bit of code because I can't think of a situation where I'll need more than one output method.

 

I shall read your link. ta.




[Mwah]
0/0
 Reply   Quote More 

 From:  Mikee   
 To:  Mikee      
34068.5 In reply to 34068.2 

Hmm. I should've read my own code before I last posted. I KNEW i wasnt going to have more than one data output object, but knew i was going to have more than one data source.

 

Gah im going insane. Far too many hours coding without a break.




[Mwah]
0/0
 Reply   Quote More 

 From:  Mikee   
 To:  THERE IS NO GOD BUT (RENDLE)     
34068.6 In reply to 34068.3 
I think im trying to think of a way to reinvent the wheel. So i'm going to have my output classes as wrappers around XmlWriters and Xsl..



[Mwah]
0/0
 Reply   Quote More 

 From:  Mikee   
 To:  Mikee      
34068.7 In reply to 34068.6 

... Except php doesnt really support xsl. and as this is open source I better think of a better way.

 

I need to stop talking to myself.




[Mwah]
0/0
 Reply   Quote More 

Reply to All    
 

1–7

Rate my interest:

Adjust text size : Smaller 10 Larger

Beehive Forum 1.5.2 |  FAQ |  Docs |  Support |  Donate! ©2002 - 2024 Project Beehive Forum

Forum Stats