You usually don’t have to programm the open and close function unless you want to add a special function to it.
read this