代码之家  ›  专栏  ›  技术社区  ›  therealhoff

实体是否应该有行为?

oop
  •  3
  • therealhoff  · 技术社区  · 17 年前

    实体应该有行为吗?或不是?

    为什么或为什么不呢?

    如果不是,这是否违反了封装?

    5 回复  |  直到 17 年前
        1
  •  6
  •   moffdub    17 年前
        2
  •  5
  •   mbinette    13 年前

    Object-Oriented Anti-Pattern - Data Objects with Behavior





    book.Write();  
    book.Print();   
    book.Publish();  
    book.Buy();  
    book.Open();   
    book.Read();  
    book.Highlight();  
    book.Bookmark();  
    book.GetRelatedBooks();   
    

    Book book = author.WriteBook();  
    printer.Print(book);  
    publisher.Publish(book);  
    customer.Buy(book);  
    
    reader = new BookReader();   
    
    reader.Open(Book);   
    
    reader.Read();  
    reader.Highlight();  
    reader.Bookmark();  
    
    librarian.GetRelatedBooks(book);  
    

        3
  •  1
  •   Guy Starbuck    17 年前

        4
  •  0
  •   Steve Moyer    17 年前

        5
  •  0
  •   Giorgio Galante    17 年前