Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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
Tweet

More Decks by smit thakkar

Other Decks in Programming

Transcript

  1. 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
  2. T O W E R O F A B S

    T R A C T I O N S
  3. 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.
  4. 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); }