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.

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group