Created
February 9, 2018 06:37
-
-
Save goyalrohit/f76ccf3a5f637dfb6f936c33fc07c9ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Order: | |
# class attribute | |
orders = [] | |
# instance attributes | |
orderid = 0 | |
shipping_address = '' | |
expedited = False | |
shipped = False | |
customer = None | |
@staticmethod | |
def test_expedited(order): | |
return order.expedited | |
@staticmethod | |
def test_not_expedited(order): | |
return not order.expedited | |
@staticmethod | |
def get_customer_name(order): | |
return order.customer.name | |
@staticmethod | |
def get_customer_address(order): | |
return order.customer.address | |
@staticmethod | |
def get_shipping_address(order): | |
return order.shipping_address | |
@staticmethod | |
def get_filtered_info(predicate, func): | |
output = [] | |
for order in Order.orders: | |
if predicate(order): | |
output.append(func(order)) | |
return output | |
@staticmethod | |
def get_expedited_orders_customer_names(): | |
return Order.get_filtered_info( | |
Order.test_expedited, | |
Order.get_customer_name | |
) | |
@staticmethod | |
def get_expedited_orders_customer_addresses(): | |
return Order.get_filtered_info( | |
Order.test_expedited, | |
Order.get_customer_address | |
) | |
@staticmethod | |
def get_expedited_orders_shipping_addresses(): | |
return Order.get_filtered_info( | |
Order.test_expedited, | |
Order.get_shipping_address) | |
@staticmethod | |
def get_not_expedited_orders_customer_names(): | |
return Order.get_filtered_info( | |
Order.test_not_expedited, | |
Order.get_customer_name | |
) | |
@staticmethod | |
def get_not_expedited_orders_customer_addresses(): | |
return Order.get_filtered_info( | |
Order.test_not_expedited, | |
Order.get_customer_address | |
) | |
@staticmethod | |
def get_not_expedited_orders_shipping_addresses(): | |
return Order.get_filtered_info( | |
Order.test_not_expedited, | |
Order.get_shipping_address) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment