cancel
Showing results for 
Search instead for 
Did you mean: 
Knowledge Sharing Hub
Dive into a collaborative space where members like YOU can exchange knowledge, tips, and best practices. Join the conversation today and unlock a wealth of collective wisdom to enhance your experience and drive success.
cancel
Showing results for 
Search instead for 
Did you mean: 

is it possible to have a class level separation in databricks or implement a design pattern in datab

alexgv12
New Contributor III

if you have thought about making your code inside databricks and notebooks more reusable and organized and you have thought about implementing a design pattern or class level separation in databricks the answer is yes, I am going to tell you the details of how to do it, the advantages and disadvantages.


if it is possible to handle different notebooks where you implement your logic at the class level or patterns as you want to implement it

with the sentence %run ../Folder/name_notebook you can make the "import" of your class, what this sentence does is that it executes your notebook and if there you have the implementation of a class you can make use of it.

benefits

  • more organized code
  • reuse code
  • maintainability of the solution
  • use of good programming practices
  • being able to access complex objects that help you perform processes

 

disadvantages

  • defining a large class in a single cell
  • when you are managing a version control you may not be able to see the changes from databricks because usually the classes are very large so you will have to commit to see the changes directly in the version control or go to the specific notebook and look up the history
  • error checking in some occasions or as you consume your methods or classes it may be complex to check errors or debug the code.

 

1 REPLY 1

-werners-
Esteemed Contributor III

tnx! I have spent quite some time on figuring out what the best way is. Your approach is certainly a valid one.
Myself I prefer to package reused classes in a jar (we mainly code in scala). Works fine too.

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!