How can I make these functions work following OOP Principles?

I have several functions/methods in a class that are kind of connected. I am building a class that mimics terminal commands and links. However, someone told me this is not proper OOP. How can I separate these methods to work independently. Methods shouldn't call other methods. Correct?

class directory:
  current_path = []
  hold_files = [
    'test1.txt', '',
    {'/desktop': ['computer.txt','tfile.doc',
        '/pictures': [

#recursively delete folder (if dot in)
  def delete(itself):
    #if dictionary, call self, else delete
    del itself


  # Join list together to produce new link, basically return the added folder to the link
  def concatenate(self):
      new_link ="".join(current_path)
      return new_link

#strip slashes and place in list 
  def adjust_link(self, paths):
      new_string = ""

      # shorten link, if someone uses cd .., basically go back to previous folder
      if paths == "cd ..":

      #extend link, if someone is cding into another folder, remove /'s and append to separate list 
      elif "cd " in paths:
          paths = paths[3:]
          for slash in paths:
              if slash == "/":
                  new_string = ""
      # This shouldn't be here as OOP must be separated but this calls the other function to concatenate a new link
      stripped = concatenate()
      return stripped

#returns link
  def link(self, paths):
    address_location = adjust_link(paths)
    return address_location"cd desktop/peace")"cd pictures")"cd ..")

Thank you.

*Also, this is not a refactoring question. I already asked on stack exchange code review and they told me to come here. Code does not work.

Edit 2: why won't "" work?

1 answer

  • answered 2020-08-11 01:05 RufusVS

    "I have a program here and I want to convert it to OOP" is not usually how it's done: "I have a problem I want to solve using OOP" is usually the approach. It looks like you are creating something that will traverse an internal directory structure. So a skeleton might look like:

    class DirectoryTraverser:
         def __init__(self, directory_tree):
             self.hold_files = directory_tree
             self.current_path = []
         def... #  all your other functions
    # then to use it might look like:
    # create a directory traversal object with directory tree
    dt = DirectoryTraverser(hold_files)  "cd desktop/peace")"cd pictures")"cd ..")