abstraction

Working with Sets as Functions

喜夏-厌秋 提交于 2019-12-01 23:44:12
From a FP course: type Set = Int => Boolean // Predicate /** * Indicates whether a set contains a given element. */ def contains(s: Set, elem: Int): Boolean = s(elem) Why would that make sense? assert(contains(x => true, 100)) Basically what it does is provide the value 100 to the function x => true . I.e., we provide 100, it returns true . But how is this related to sets? Whatever we put, it returns true . Where is the sense of it? I understand that we can provide our own set implementation/function as a parameter that would represent the fact that provided value is inside a set (or not) -

package visibility [closed]

旧城冷巷雨未停 提交于 2019-12-01 17:30:43
Why use package visibility (the default), unless the class should be public in java As Rostislav Matl said, it's useful for when you want to make something that doesn't form part of your package's interface. As an example, imagine you have a package and it provides an interface and at least one concrete implementation of a service. People who use this service are going to care about the interface you provide and use one of the concrete classes you provide but they aren't going to care about much else beyond that. Our service has to talk to a database and it needs to be able to map the result

What is the difference between abstract class and pure abstract class in C++?

随声附和 提交于 2019-12-01 14:07:23
问题 Example: Iterators are pure abstractions: Anything that behaves like an iterator is an iterator. What does it mean? 回答1: An abstract class has at least one pure virtual function. This is standard C++ terminology. Some people use the term pure abstract class to describe a class that has nothing but pure virtual functions (in other words, no data members and no concrete functions). This is equivalent to Java interfaces. Now to your actual question: Iterators are pure abstractions: Anything that

JAVA - Abstraction

主宰稳场 提交于 2019-12-01 12:30:30
I am little confused about abstraction in java. I have checked many pages stating that abstraction is data hiding(Hiding the implementation). What I understand about abstraction is it is 'partial implementation'. Just define what you are going to need in an abstract class/interface and afterwards extend/implement them and add your own functionality. What I don't understand is how this is a data hiding? You are going to get access to the code once you implement the class/interface and you will modify it according to your need. I have checked many questions, articles on this but still confused

python equivalent of java OutputStream?

不羁岁月 提交于 2019-12-01 07:39:50
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? "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 use the interface of file-like objects. FWIW, the standard input/output/error streams are represented by

Polymorphic Numerics on .Net and In C#

人盡茶涼 提交于 2019-12-01 05:46:08
问题 It's a real shame that in .Net there is no polymorphism for numbers, i.e. no INumeric interface that unifies the different kinds of numerical types such as bool, byte, uint, int, etc. In the extreme one would like a complete package of abstract algebra types. Joe Duffy has an article about the issue: http://www.bluebytesoftware.com/blog/CommentView,guid,14b37ade-3110-4596-9d6e-bacdcd75baa8.aspx How would you express this in C#, in order to retrofit it, without having influence over .Net or C#

Why higher order procedures?

廉价感情. 提交于 2019-11-30 21:28:19
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 to define ProcA , like: (define (Proc a b c x) ( #| method body -- does not return any procedure |# )

Clean Code: Should Objects have public properties?

∥☆過路亽.° 提交于 2019-11-30 17:00:59
I'm reading the book "Clean Code" and am struggling with a concept. When discussing Objects and Data Structures, it states the following: Objects hide their data behind abstractions and expose functions that operate on that data. Data Structures expose their data and have no meaningful functions. So, what I'm getting from this is that I shouldn't have any public properties on my object, I should only have methods that perform operations on the properties. If I do need to access properties, they should be on a Data Structure, which could be returned from a method on my object? With this

Clean Code: Should Objects have public properties?

不羁的心 提交于 2019-11-30 16:35:46
问题 I'm reading the book "Clean Code" and am struggling with a concept. When discussing Objects and Data Structures, it states the following: Objects hide their data behind abstractions and expose functions that operate on that data. Data Structures expose their data and have no meaningful functions. So, what I'm getting from this is that I shouldn't have any public properties on my object, I should only have methods that perform operations on the properties. If I do need to access properties,

Abstraction and abstract in java

£可爱£侵袭症+ 提交于 2019-11-30 08:42:56
问题 I am a java developer with good understanding of Object orientation concepts( or maybe, I think like that ). And right now I am learning design patterns (From Head first design patterns). I have been reading about OOPS concept abstraction to understand it briefly, and reading more about it has made me more confusing than I earlier was. As I understand, abstraction refers to hiding the internal details of the program while exposing the interface to other programmers without worries of internal