<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Why Objects?
Provide modularity and reuse through hierarchical structures
Object oriented programming is a different way of thinking.
Programming With Objects
Step1:  Initial concepts
An object is a container of data (attributes) and code (methods)
A class is a template for creating objects
Reuse is provided by
Step2:  Attributes
Step3:  Attributes are data associated with an object (instance) or class. Object attributes (and methods) are specified by using "self". Instance attributes and methods are accessed using the dot "." operator.
Step4:  EXERCISE
Step7:  A class diagram provides a more compact representation of a class. There are three sections.
- Class name
- Attributes
- Methods
Instance methods
- functions associated with the objects constructed for a class
- provide a way to transform data in objects
- use instance attributes (references to variables beginning with "self.")
Step9:  EXERCISE
Step10:  Exercise
Step11:  Subclasses can have their own methods.
Exercise
Step12:  The diamond arrow is a "has-a" relationship. For example, the Controller has-a ATMInput. This means that a Controller object has an instance variable for an ATMInput object.
Interaction Diagram for the ATM System
An interaction diagram specifies how components interact to achieve a use case. 
Interactions are from one object to another object, indicating that the first object calls a method in the second object.
Rules for drawing lines in an interaction diagram
Step13:  Look at Objects/ATMDiagrams.pdf for a solution.
What Else in Design?
Other diagrams
<ASSISTANT_TASK:>
Python Code:
from IPython.display import Image
Image(filename='Classes_vs_Objects.png') 
Explanation: Why Objects?
Provide modularity and reuse through hierarchical structures
Object oriented programming is a different way of thinking.
Programming With Objects
End of explanation
# Definiting a Car class
class Car(object):
    pass
Explanation: Initial concepts
An object is a container of data (attributes) and code (methods)
A class is a template for creating objects
Reuse is provided by:
reusing the same class to create many objects
"inheriting" data and code from other classes
End of explanation
from IPython.display import Image
Image(filename='ClassAttributes.png') 
Explanation: Attributes
End of explanation
class Car(object):
    
    # The following method is called when the class
    # is created or "constructed". The variables "self.x" refers
    # to the variable "x" in a created object.
    def __init__(self, color, car_type, speed):
        self.color = color
        self.car_type = car_type
        self.speed = speed
class Car(object):
    
    # The following method is called when the class
    # is created or "constructed". The variables "self.x" refers
    # to the variable "x" in a created object.
    def __init__(self, color, car_type, speed):
        self.color = color
        self.car_type = car_type
        self.speed = speed
# Creating an object for a class with arguments in the __init__ method
car = Car("Blue", "HatchBack", 100)
car.color
# Creating an object for a class with arguments in the __init__ method
joe_car = Car("Blue", "Sedan", 100)
dave_car = Car("Red", "Sports", 150)
print ("Type of joe_car is %s. Type of dave_car is %s"% (type(joe_car), type(dave_car)))
# Accessed instance attributes
joe_car = Car("Blue", "Sedan", 100)
print ("Type of joe_car has (color, type, speed)=%s." % str((joe_car.color, joe_car.car_type, joe_car.speed)))
Explanation: Attributes are data associated with an object (instance) or class. Object attributes (and methods) are specified by using "self". Instance attributes and methods are accessed using the dot "." operator.
End of explanation
from IPython.display import Image
Image(filename='InstanceMethods.png') 
#Class diagram
from IPython.display import Image
Image(filename='SingleClassDiagram.png', width=200, height=200) 
Explanation: EXERCISE: Change the constructor for Car to include the attribute "doors".
Instance Methods
End of explanation
class Car(object):
    
    def __init__(self, color, car_type, speed):
        
        :param str color:
        :param str car_type:
        :param int speed:
        
        self.color = color
        self.car_type = car_type
        self.speed = speed
        
    def start(self):
        print ("%s %s started!" % (self.color, self.car_type))
        
    def stop(self):
        pass
        
    def turn(self, direction):
        
        :parm str direction: left or right
        
        pass
car = Car("Blue", "Sedan", 100)
car.start()
Explanation: A class diagram provides a more compact representation of a class. There are three sections.
- Class name
- Attributes
- Methods
Instance methods
- functions associated with the objects constructed for a class
- provide a way to transform data in objects
- use instance attributes (references to variables beginning with "self.")
End of explanation
from IPython.display import Image
Image(filename='SimpleClassHierarchy.png', width=400, height=400) 
# Code for inheritance
class Sedan(Car):
    # Sedan inherits from car
    
    def __init__(self, color, speed):
        
        :param str color:
        :param int speed:
        
        super().__init__(color, "Sedan", speed)
        
    def play_cd(self):
        print ("Playing cd in %s sedan" % self.color)
sedan = Sedan("Yellow", 1e6)
sedan.play_cd()
sedan.car_type
joe_car = Sedan("Blue", 100)
print ("Type of joe_car has (color, type, speed)=%s." % str((joe_car.color, joe_car.car_type, joe_car.speed)))
Explanation: EXERCISE: Implement the stop and turn methods. Run the methods.
Inheritance
Inheritance is a common way that classes reuse data and code from other classes. A child class or derived class gets attributes and methods from its parent class.
Programmatically:
- Specify inheritance in the class statement
- Constructor for derived class (class that inherits) have access to the constructor of its parent.
Inheritance is represented in diagrams as an arror from the child class to its parent class.
End of explanation
from IPython.display import Image
Image(filename='ClassInheritance.png', width=400, height=400) 
Explanation: Exercise: Implement SportsCar and create dave_car from SportsCar. Print attributes of dave_car.
End of explanation
from IPython.display import Image
Image(filename='ATMClassDiagram.png', width=400, height=400) 
Explanation: Subclasses can have their own methods.
Exercise: Add the play_cd() to Sedan and play_bluetooth() method to SportsCar. Construct a test to run these methods.
What Else?
Class attributes
Class methods
Object Oriented Design
A design methodology must specify:
- Components: What they do and how to build them
- Interactions: How the components interact to implement use cases
Object oriented designed
- Components are specified by class diagrams.
- Interactions are specified by interaction diagrams.
Class diagram for the ATM system
End of explanation
from IPython.display import Image
Image(filename='ATMAuthentication.png', width=800, height=800) 
Explanation: The diamond arrow is a "has-a" relationship. For example, the Controller has-a ATMInput. This means that a Controller object has an instance variable for an ATMInput object.
Interaction Diagram for the ATM System
An interaction diagram specifies how components interact to achieve a use case. 
Interactions are from one object to another object, indicating that the first object calls a method in the second object.
Rules for drawing lines in an interaction diagram:
- The calling object must know about the called object.
- The called object must have the method invoked by the calling object.
End of explanation
from IPython.display import Image
Image(filename='SciSheetsCoreClasses.png', width=300, height=30) 
Explanation: Look at Objects/ATMDiagrams.pdf for a solution.
What Else in Design?
Other diagrams: state diagrams, package diagrams, ...
Object oriented design patterns
Complex Example of Class Hierarchy
End of explanation
<END_TASK>