官术网_书友最值得收藏!

How it works...

We started by defining VehicleProtocol that has a list of properties and functions that every vehicle should have. In properties, we have two types of properties: name, which is marked as {get set}, and canFly, which is marked as {get}. When you mark a property {get set}, it means it's gettable and settable, whereas {get} means it only gettable, in other words, it's a read-only property. Then, we added four methods, out of which three methods-numberOfWheels(), move(), and stop()-are instance methods. The last one-popularBrands()- marked as static is a type method. Types methods can be called directly with type name, and there is no need to have instance to call it.

Then, we created two new classes, Bicycle and Car, which conform to VehicleProtocol, and each one will have different implementations.

主站蜘蛛池模板: 邻水| 阿荣旗| 泾川县| 莱西市| 乐都县| 离岛区| 麟游县| 蒲城县| 沙湾县| 合川市| 彭山县| 龙川县| 湖南省| 云阳县| 兴城市| 双江| 大英县| 丹阳市| 平罗县| 桦南县| 昌江| 江门市| 九江市| 根河市| 六盘水市| 成武县| 宁蒗| 娄底市| 鄂托克旗| 庆阳市| 五大连池市| 米泉市| 平乡县| 惠州市| 湖南省| 名山县| 林西县| 颍上县| 遂川县| 于都县| 余干县|