zoukankan      html  css  js  c++  java
  • 重新梳理Python基础(10)

    1. 今天学了一些概念。(书的第41~43章)

    用这个方法可以分清楚class、object、instance

    ## Animal is-a object (yes, sort of confusing) look at the extra credit
    class Animal(object):
        pass
    
    ## Dog is-a animal, it has-a name
    class Dog(Animal):
    
        def __init__(self, name):
            ## ??
            self.name = name
    
    ## Cat is-a animal, it has-a name
    class Cat(Animal):
    
        def __init__(self, name):
            ## ??
            self.name = name
    
    ## Person is-a object, it has-a name and pet
    class Person(object):
    
        def __init__(self, name):
            ## ??
            self.name = name
    
            ## Person has-a pet of some kind
            self.pet = None
    
    ## Employee is-a Person, it has-a name and salary
    class Employee(Person):
    
        def __init__(self, name, salary):
            ## ?? hmm what is this strange magic?
            super(Employee, self).__init__(name)
            ## ??
            self.salary = salary
    
    ## Fish is-a object
    class Fish(object):
        pass
    
    ## Salmon is-a Fish
    class Salmon(Fish):
        pass
    
    ## Halibut is-a Fish
    class Halibut(Fish):
        pass
    
    
    ## rover is-a Dog
    rover = Dog("Rover")
    
    ## satan is-a Cat
    satan = Cat("Satan")
    
    ## mary is-a Person
    mary = Person("Mary")
    
    ## mary has-a pet, satan
    mary.pet = satan
    
    ## frank is-a employee, it has-a salary 120000
    frank = Employee("Frank", 120000)
    
    ## frank has-a pet, rover
    frank.pet = rover
    
    ## flipper is-a fish
    flipper = Fish()
    
    ## crouse is-a salmon
    crouse = Salmon()
    
    ## harry is-a halibut
    harry = Halibut()

    用这种方式可以比较清楚的明白对象、类和实例的概念。

    2. OOP

    1. Write or draw about the problem.
    2. Extract key concepts from #1 and research them.
    3. Create a class hierarchy and object map for the concepts.
    4. Code the classes and a test to run them.
    5. Repeat and refine.
  • 相关阅读:
    wordpress通过$wpdb获取一个分类下所有的文章
    WordPress的摘要显示方式
    WordPress简洁的SEO标题、关键词和描述
    WordPress获取特色图像的链接地址
    WordPress的Bootstrap面包屑导航
    destoon 6.0 手机站支持在所有浏览器访问
    dede织梦5.7的安全防护设置
    WordPress主题制作:基础样式文件
    LInux常用到的命令(面试)
    1030 完美数列 (25分) PAT-B
  • 原文地址:https://www.cnblogs.com/dollarzhaole/p/2976451.html
Copyright © 2011-2022 走看看