Python language basics 80: polymorphism through interfaces

Introduction

In the previous post we started looking at one of the most important ideas of object oriented design: polymorphism. Polymorphism is a way to represent common features through objects. The implementation details of the related functions through those objects do not matter to the caller. E.g. all vehicles can be accelerated. In cars you press the gas pedal, you pedal faster on a bicycle and do something else on aeroplanes. The exact acceleration process is an implementation detail of the Car, Bicycle and Aeroplane classes probably represented by a function called “accelerate” that accepts some numeric argument, such as “how_fast”.

In this post we’ll look at interface type polymorphism in Python.

Read more of this post

Python language basics 79: polymorphism basics

Introduction

In the previous post we discussed composite classes in Python. Composite classes are classes that are at least partly made up of other classes. We saw that there wasn’t anything special about adding other classes as class level properties to a class. In our example we constructed a Name, an Address and a Telephone classes that were all parts of the Person class.

In this post we’ll start looking into the key object-oriented idea of polymorphism. This is a relatively large topic and will span a couple of posts. In this post we’ll look at some theory first to pave the way for the code examples in upcoming posts.

Read more of this post

Python language basics 78: composite classes

Introduction

In the previous post we looked at property getters in Python. They are “normal” methods but they have a special purpose, namely to read the values of class level properties. Getters and setters are not as strictly defined as in other popular languages like Java and C# and you’ll come across various solutions for those types of special functions in your Python projects.

In this post we’ll look at composite classes.

Read more of this post

Python language basics 77: class property getters

Introduction

In the previous post we looked at a special group of class level methods called setters. We saw that they were really not different from other class level methods. The single major difference lies in the purpose of setters, which is to let external users of a class provide a value for a class property. We also discussed that a setter may not be available for immutable, read-only or otherwise complex class properties.

In this post we’ll look at the counterpart of setters called getters.

Read more of this post

Python language basics 76: class property setters

Introduction

In the previous post we looked at class level methods. We saw that they weren’t much different from “normal” methods. The fact that the first input parameter is “self” is what differentiates class level methods. Also, they can be called on an instance of a class, i.e. an instantiated object. The extra properties that the method needs are provided after “self”.

In this post we’ll look at a special group of class methods: setters.

Read more of this post

Python language basics 75: class level methods

Introduction

In the previous post we looked at the basics of validation. In particular we looked at an example where the values sent to the initialiser were validated in code. Validation is important in order to stop invalid values being assigned to class level variables. However, validation can occur just about anywhere in code. E.g. if a numeric input is required from the user then you’d almost certainly need to validate it so that the code doesn’t stop with an exception when trying to convert the string input into a number.

In this post we’ll quickly look at class level methods.

Read more of this post

Python language basics 74: validating class level properties

Introduction

In the previous post we discussed class level properties in some detail. The most important detail we learned is that there are only public members in a Python class. Properties can be added to “self” on the fly within the class but those properties will be visible to all external callers. So all you’ve learnt about access modifiers from your Java course, such as private or public is not applicable in Python.

In this post we’ll explore the basics of validating the values that are sent into the object initialiser. Validation is a large topic so consider this only as a light introduction.

Read more of this post

ultimatemindsettoday

A great WordPress.com site

iReadable { }

.NET Tips & Tricks

Robin Sedlaczek's Blog

Love to use Microsoft Technologies

HarsH ReaLiTy

A Good Blog is Hard to Find

Ricos Blog zu Softwaredesign- und architektur

Ideen und Gedanken rund um Softwaredesign und -architektur, Domain-Driven Design, C# und Windows Azure

the software architecture

thoughts, ideas, diagrams,enterprise code, design pattern , solution designs

Technology Talks

on Microsoft technologies, Web, Android and others

Software Engineering

Web development

Disparate Opinions

Various tidbits

chsakell's Blog

Anything around ASP.NET MVC,WEB API, WCF, Entity Framework & AngularJS

Cyber Matters

Bite-size insight on Cyber Security for the not too technical.

Guru N Guns's

OneSolution To dOTnET.

Johnny Zraiby

Measuring programming progress by lines of code is like measuring aircraft building progress by weight.

%d bloggers like this: