Slide 1

Slide 1 text

Writing clean abstractions Smit Thakkar

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

What is an abstraction?

Slide 4

Slide 4 text

T O W E R O F A B S T R A C T I O N S

Slide 5

Slide 5 text

Abstractions gives us leverage. It lets us do much more

Slide 6

Slide 6 text

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.

Slide 7

Slide 7 text

All sufficiently useful abstractions leak, Examples

Slide 8

Slide 8 text

Formation of bad abstraction

Slide 9

Slide 9 text

Example #2 public interface A { public void Add(Customer customerToAdd); public void Delete(Customer customerToDelete); public void Update(Customer customerToUpdate); public IEnumerable 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 GetAllCustomers(); public IEnumerable GetAllCustomersAsEnumerable(); public bool Connect(); public List GetAllDatabaseRecords(bool isSqlServer); public List GetSingleCustomer(int customerId); public void Close(int handle, bool shouldClose); public void Close(int handle, bool shouldClose, bool alt); }

Slide 10

Slide 10 text

So how can I go around building a good abstraction?

Slide 11

Slide 11 text

SID ● Single Responsibility ● Interface Segregation ● Dependency Inversion

Slide 12

Slide 12 text

Example:

Slide 13

Slide 13 text

Things can come crashing down if you do it wrong

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content