课程: C# Practice: Interfaces and Abstract Classes
Solution: Refactor a fat interface
- [Instructor] The code challenge was to refactor this large interface called IBigPrinter into smaller, leaner interfaces. So the first step that I did in my code was I commented out this interface IBigPrinter. Now, remember that it has one property called printer name, and two methods, one called PrintDoc and one called ScanDoc. Now, what I'm going to do is move each one of these items or each one of these members into a separate interface. So up here I created three new interfaces. One's called IPrintDevice and it's where I've defined the printer name property. Then I have IPrinter, which has PrintDoc, and IScanner, which has ScanDoc. Then I'm using a principle of a base interface, so this IPrint device is used as the base interface for IPrinter and for ScannerDoc. That way I only have to implement, or only have to define I should say, the printer name property in one spot. Once I've got my three skinny interfaces defined, then I go up to my color printer and I implement the IPrinter interface. And that means I have to implement the printer name and the PrintDoc, but I no longer need to implement this ScanDoc method. So that's how I chose to refactor this fat interface.