abstraction

python equivalent of java OutputStream?

六月ゝ 毕业季﹏ 提交于 2019-12-19 08:29:06
问题 Is there a Python equivalent / pseudo-equivalent to java's OutputStream or PrintWriter? I want to be able to have a handle that represents either a stream like stdout/sterr, or a file, or something else (a pipe or a socket or a dummy sink) and abstract away what kind of thing it is, so I can just send output to it. How can I do this? 回答1: "Abstracting away what type it is" happens automatically in Python - it's called 'duck typing'. Just pass any file-like object to the function, and have it

Why higher order procedures?

非 Y 不嫁゛ 提交于 2019-12-19 03:22:23
问题 So if a language provides higher order procedure then I can have procedure that returns procedure. Something like: (define (Proc a b c) (lambda (x) ( #| method body here in terms of a b c and x |# ))) To create new procedure, I would just do something like: (define ProcA (Proc a1 b1 c1)) ; Would create ProcA that has 1 argument Similar task could be done in a language which does not support higher order procedure by defining Proc that takes 4 instead of 3 arguments and calling this procedure

Why higher order procedures?

妖精的绣舞 提交于 2019-12-19 03:22:09
问题 So if a language provides higher order procedure then I can have procedure that returns procedure. Something like: (define (Proc a b c) (lambda (x) ( #| method body here in terms of a b c and x |# ))) To create new procedure, I would just do something like: (define ProcA (Proc a1 b1 c1)) ; Would create ProcA that has 1 argument Similar task could be done in a language which does not support higher order procedure by defining Proc that takes 4 instead of 3 arguments and calling this procedure

How much abstraction is too much?

烂漫一生 提交于 2019-12-18 09:54:21
问题 In an object-oriented program: How much abstraction is too much? How much is just right? I have always been a nuts and bolts kind of guy. I understood the concept behind high levels of encapsulation and abstraction, but always felt instinctively that adding too much would just confuse the program. I always tried to shoot for an amount of abstraction that left no empty classes or layers. And where in doubt, instead of adding a new layer to the hierarchy, I would try and fit something into the

Compiling vs Transpiling

大兔子大兔子 提交于 2019-12-17 22:18:33
问题 While searching about the difference, I came across these definitions: Compiling is the general term for taking source code written in one language and transforming into another. Transpiling is a specific term for taking source code written in one language and transforming into another language that has a similar level of abstraction. I understand what Abstraction is. But what does "similar level of abstraction" mean in the above definition? And how do we find the level of abstraction in a

Difference between Encapsulation and Abstraction

我的未来我决定 提交于 2019-12-17 17:24:30
问题 I had an interview today. I had a question from OOP , about the difference between Encapsulation & Abstraction ? I replied her to my knowledge that Encapsulation is basically to bind data members & member functions into a single unit called Class . Whereas Abstraction is basically to hide complexity of implementation & provide ease of access to the users. I thought she would be fine with my answer. But she queried, if the purpose of both are to hide information then what is the actual

How abstraction and encapsulation differ?

↘锁芯ラ 提交于 2019-12-17 03:48:11
问题 I am preparing for an interview and decided to brush up my OOP concepts. There are hundreds of articles available, but it seems each describes them differently. Some says Abstraction is "the process of identifying common patterns that have systematic variations; an abstraction represents the common pattern and provides a means for specifying which variation to use" (Richard Gabriel). and is achieved through abstract classes. Some other says Abstraction means to show only the necessary details

Empty virtual method on base class VS abstract methods [closed]

我的梦境 提交于 2019-12-14 03:09:24
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 years ago . I couldn't find a question that was not too specific to some case, so I'll try to make this very generic. We need an extractor base class to a set of documents, for example. Each document has its specific properties, but they're ultimately documents. So we want to provide

Abstracting away from data structure implementation details in Clojure

谁说我不能喝 提交于 2019-12-13 11:40:07
问题 I am developing a complex data structure in Clojure with multiple sub-structures. I know that I will want to extend this structure over time, and may at times want to change the internal structure without breaking different users of the data structure (for example I may want to change a vector into a hashmap, add some kind of indexing structure for performance reasons, or incorporate a Java type) My current thinking is: Define a protocol for the overall structure with various accessor methods

Confusion regarding having inheritance or not in my design

故事扮演 提交于 2019-12-13 09:20:00
问题 I have requirement like this that Driver and Mechanic can Start,ApplyBrakes,ChangeGear and Stop the Car . I also have 2 additional functionalities that is Mechanic is the only one who can ChangeOil and AdjustBrakes and Driver should not be able to do this. Based on this,this is what I have prepared : interface IDrivable { void Start(); void ApplyBrakes(); void ChangeGear(); void Stop(); } interface IFixable { void ChangeOil(); void AdjustBrakes(); } public class Car : IDrivable, IFixable {