Deutsch
Germany.ruФорумы → Архив Досок→ Программирование

редактирование - merge()... в синглетоне

22.11.12 12:27
Re: редактирование - merge()... в синглетоне
 
  Posmotrim посетитель
Posmotrim
в ответ Murr 22.11.12 09:31
я бы не стал делать документ синглтоном, а просто бы обеспечил к нему доступ из уже существуюещего синглтона приложения к примеру:
    class Application 
{
private Application() {throw new NotImplementedException();}
static Application Instance {get {throw new NotImplementedException();}}
public Document ActiveDocument { get; private set; }
public void OpenDocument(Reader from)
{
if(ActiveDocument != null)
ActiveDocument.Close();
ActiveDocument = new Document(from);
}
}


Таким образом, имеем единственный объект документа в приложении(Application).
Теперь рассмотрим класс документа:

class Document
{
public Document(Reader from) { throw new NotImplementedException(); }
//Properties
//...
//Methods
//...
public void Save(Writer to) { throw new NotImplementedException(); }
public void Close() { throw new NotImplementedException(); }
public void MergeWith(Document other){ throw new NotImplementedException(); }
}


 

Перейти на