Tag Info

New answers tagged

-1

Quick Short Answer Yes, Programmers can apply the Object Oriented Programming without "Classes". Long Boring Extensive Descriptive Answer There are several variations of "Object Orientation", altought, the first concept that comes to the mind of many programmers is "Classes". Yes, Programmers can apply the Object Oriented Programming without "Classes", ...


0

Not always: it depends on the language. You've demonstrated the ability to do this in Python but (if your question is meant to be language agnostic despite the Python tag) not all languages can do this. Java, for example, mostly can't. Ignoring the class that contains main, there is no way to define arbitrary methods/fields on an object defined within main ...


5

Of course you can! The Self programming language is a dynamic prototype-based object oriented language in which everything is an object and there is no sense of classes or whatsoever. It's focused in the idea of prototypical objects and the idea of cloning them instead of having classes as templates of how to create objects. You should check ...


44

Congratulations! You rediscovered the well known fact that object orientation can be done without specific programming language support. It is basically the same way objects are introduced in Scheme in this classic text book. Note that Scheme does not have a class keyword or some kind of equivalent, and objects can be created without having even classes. ...


7

I would agree that the first definition satisfies the three points your teacher made. I do not think we need the class keyword for anything. Under the covers, what else is an object but a data structure with with different types of data and functions to work with the data? Of course, the functions are data as well.. I would go even further and say that ...


7

Forget the outer loop around for a moment, and think about the meaning of your method second_small, the abstraction it represents (I assume in your real code, you picked a more meaningful name). Then what you do in that method should depend on what if j == 'something': ... means, in contrast to that abstraction. For example, if j == 'something' is a ...


1

We are using something very similar to this. Can't you add a task that saves the data once it has completed processing them? We use Kombu to download (Consumer) and to Publish (Producer) back to RMQ and celery only has a very specific task which sort of is your case. RMQ queue A gets consumed by Consumer Message obtained by Consumer gets sent to Celery ...


-2

If your problem is only the warnings of IDE, you can avoid it using 2 solutions solution 1, meta class class ABCMeta(): def func_2(self): return 1 #any valid value, just to your IDE dont complain class MyClass1(ABCMeta): def func_1(self): return self.func_2() * 2 class MyClass5(MyClass1): def func_2(self): return ...


1

One option is to make it clear to the IDE and your users that there is a method, but you can't use the base class version: class MyClass1(object): def func_2(self): raise NotImplementedError def func_1(self): return self.func_2() * 2 You won't get warnings from intermediate classes that don't define func_2, but will get an error ...


5

If func_2 in MyClass1 doesn't contain any logic and is expected to be declared by child classes (and MyClass1 is never used directly), then making the class abstract like you did is a reasonable approach and makes the code self-documenting and explicit. If: func_2 in MyClass1 contains logic (eventually overwritten in child classes), Or MyClass1 may be ...



Top 50 recent answers are included