473,224 Members | 1,534 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,224 software developers and data experts.

Voluntary Abstract Base Classes

Hi list,

Well, the short question is: what are they? I've read Guido's python
3000 status report on
http://www.artima.com/weblogs/viewpo...?thread=208549 where he
mentions ABC's but don't quite understand what the whole story is
about.

Anyone has good use cases?

Daniel
Jun 29 '07 #1
1 1141
Daniel Nogradi wrote:
Hi list,

Well, the short question is: what are they? I've read Guido's python
3000 status report on
http://www.artima.com/weblogs/viewpo...?thread=208549 where he
mentions ABC's but don't quite understand what the whole story is
about.

Anyone has good use cases?

Daniel
My interpretation of his description is that this is a way to check for
quack likes a duck behavior.

Say I want a function to check if something behaves like a slice, but
don't want to resort to checking for explicit inheritence, I might now
have to do something like (factoring out the checking):
def is_slice_like(candidate):
for att in 'start', 'stop', 'step', 'indices':
if not hasattr(candidate, att):
return False
return True

def doit(anarg):
if not is_slice_like(anarg):
raise Exception, 'Must give something like a slice.'
do_rest_of_it()
However, with an ABC, you could define what it means to be slice-like by
defining a slice-like ABC (e.g. SliceLike) and then virtually inheriting
from this ABC:
# assuming abstract inheritence syntax is the same as regular
class MySlice(SliceLike):
# etc.

def doit(anarg):
if not issubclass(anarg.__class__, SliceLike):
raise Exception, 'Must give something SliceLike.'

def main():
anarg = MySlice(1,2,3)
doit(anarg)
With ABCs, the concept of slice-like is more formalized and transparent
than the attribute checking done in is_slice_like and is far more
flexible than explicit type checking.

The concept seems to be borrowed from Java interfaces.

But I'm ready to be corrected on my interpretation.

James
Jun 29 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dave Veeneman | last post by:
Is is legal to declare abstract members in non-abstract classes? How about non-abstract members in abstract classes? I am writing a base class with three derived classes. The base class will...
18
by: Bradley | last post by:
I'm trying to determine if there's a general rule for when an Interface should used vs. an Abstract Class. Is there any design advantage to using one or the other? Brad
9
by: Sean Kirkpatrick | last post by:
To my eye, there doesn't seem to be a whole lot of difference between the two of them from a functional point of view. Can someone give me a good explanation of why one vs the other? Sean
0
by: emin.shopper | last post by:
I had a need recently to check if my subclasses properly implemented the desired interface and wished that I could use something like an abstract base class in python. After reading up on metaclass...
2
by: Zytan | last post by:
I know that WebRequest.GetResponse can throw WebException from internet tutorials. However in the MSDN docs: http://msdn2.microsoft.com/en-us/library/system.net.webrequest.getresponse.aspx It...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.