What steps can be taken to identify which parts of a script belong together when organizing them into classes and methods?

When organizing parts of a script into classes and methods, it is important to identify which parts belong together based on their functionality or purpose. One way to do this is to group related code together that performs a specific task or shares common functionality. By organizing code in this way, it becomes easier to maintain, understand, and reuse.

class User {
    public function login($username, $password) {
        // code for user login functionality
    }

    public function logout() {
        // code for user logout functionality
    }
}

class Database {
    public function connect() {
        // code for database connection
    }

    public function query($sql) {
        // code for executing database queries
    }
}