Writing Clean Abstractions

Writing Clean Abstractions

Abstractions make things appear simple. This is one of the main concepts behind OOP. So what is it?! This talk will provide some guidelines on how to build abstractions that are extendable and scalable. Throughout the talk using examples Smit will try to differentiate between good and bad abstractions. He will talk about various ways of how to write clean, non-leaky and mature abstractions and present examples of same.


smit thakkar

August 03, 2019


  1. Writing clean abstractions Smit Thakkar

  2. README.md • Software Engineer at Dubizzle • Founder of Zypher

    • Open source organizations I have been part of ◦ Gluster ◦ Ngui • Former Chapter Lead of GDG Gandhinagar • Github: github.com/smitthakkar96 • Linkedin: linkedin.com/in/smitthakkar96 • https://zypher.tech
  3. What is an abstraction?

  4. T O W E R O F A B S

    T R A C T I O N S
  5. Abstractions gives us leverage. It lets us do much more

  6. Strong Abstractions vs Weak Abstractions They are classified based on

    the degree to which complexity is encapsulated. - A strong abstraction encapsulates lot of complexity not necessarily a good thing - A weak abstraction on the other hand encapsulates very little complexity but it’s not necessarily a bad thing.
  7. All sufficiently useful abstractions leak, Examples

  8. Formation of bad abstraction

  9. Example #2 public interface A { public void Add(Customer customerToAdd);

    public void Delete(Customer customerToDelete); public void Update(Customer customerToUpdate); public IEnumerable<Customer Find(Predicate<Customer> searchCriteria); } public interface A { public void Add(int customerId, string customerName); public void Delete(int customerId); public void Delete(Customer customer, string customerId, bool shouldValidate = false); public void Update(Customer customer); public void OpenDatabase(string connection); public bool ShouldUseFileInsteadOfDatabase { get; set; } public List<Customer> GetAllCustomers(); public IEnumerable<Customer> GetAllCustomersAsEnumerable(); public bool Connect(); public List<DatabaseRecord> GetAllDatabaseRecords(bool isSqlServer); public List<DatabaseRecord> GetSingleCustomer(int customerId); public void Close(int handle, bool shouldClose); public void Close(int handle, bool shouldClose, bool alt); }
  10. So how can I go around building a good abstraction?

  11. SID • Single Responsibility • Interface Segregation • Dependency Inversion

  12. Example:

  13. Things can come crashing down if you do it wrong

  14. None
  15. None