Open/Closed principle: Classes should be open for extension but closed for modification.If a function becomes too complicated, please check whether it’s time to divide some classes into parts. Try to make every class responsible for a single part of the functionality provided by the software. Single responsibility principle: A class should have just one reason to change.Composition represents the “has a” relationship between classes.Inheritance represents the “is a” relationship between classes.When overriding methods, you need to make sure the new behavior is compatible with the pattern class. A subclass cannot reduce the interface of the superclass. However, it also comes with caveats especially when you have tons of classes and changing anything is pretty hard. Favor composition over inheritance: Inheritance is probably the most obvious and easy way of reusing code between classes.Make the second class depend on this new interface rather than the concrete class.Make the class that is a dependency implement this interface.Describe these methods in a new interface or abstract class.Determine what exactly one object needs from the other.When set up collaboration between objects: This can help with the extensibility in the future. For example, when coding the relation between Company and individual employees such as Data Scientists (DS) and Software Engineers (SE), instead of connecting Company and DS/SE classes directly, write an Employee abstract class and connect Company with Employee class. Program to an interface, not an implementation: Depend on abstractions, not on concrete classes.Encapsulation can be done on either a method level or a class level. The main objective is to minimize the effect caused by changes. Encapsulate what varies: identify the aspects that varies and separate them from what stays the same.Making your library of software easily extend saves your time in the long run. Extensibility: Change is a common thing in a programmer’s life.When writing a function or class, keep code reuse in mind. Code reuse: Reusing code can help reduce the development cost and time.Here I summarized some good software design principles from the book Dive into Design Patterns by Alexander Shvets, which is very helpful to me for understanding design patterns in object-orient programming. Having good software design mindset can help data scientists better connect with engineers and make the R&D to production transition smoother. In industry, every model developed by a data scientist will eventually be put into production in an idea case. Good design principles help you boost productivity!Īs a data scientist, software design is a weak point of my skill sets.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |