abstraction

Why is Haskell missing “obvious” Typeclasses

荒凉一梦 提交于 2019-11-27 09:50:54
问题 Consider the Object-Oriented Languages: Most people coming from an object-oriented programming background, are familiar with the common and intuitive interfaces in various languages that capture the essence of Java's Collection & List interfaces. Collection refers to a collection of objects which doesn't necessarily have an natural ordering/indexing. A List is a collection which has a natural ordering/indexing. These interfaces abstract many library data-structures in Java, as do their

Is returning IList<T> worse than returning T[] or List<T>?

左心房为你撑大大i 提交于 2019-11-27 09:18:48
问题 The answers to questions like this: List<T> or IList<T> always seem to agree that returning an interface is better than returning a concrete implementation of a collection. But I'm struggling with this. Instantiating an interface is impossible, so if your method is returning an interface, it's actually still returning a specific implementation. I was experimenting a bit with this by writing 2 small methods: public static IList<int> ExposeArrayIList() { return new[] { 1, 2, 3 }; } public

What is abstraction? [closed]

一个人想着一个人 提交于 2019-11-27 08:58:29
I see abstraction in processes. I see abstraction in data. I see that abstraction is losing the unimportant details. I see that abstraction is giving a group of elements a name and treating them as one unit. (But I don't know why that is considered abstraction. So, please I need clarification on this particular point) I know there are also levels of abstraction, and although the name implies something, I don't have a practical example, and I can't think of a specific one I'm confused about the definition of abstraction. Can somebody write a comprehensive article? Scratch that. Can somebody

What is the benefit of a 'promise' abstraction in CommonJS?

陌路散爱 提交于 2019-11-27 05:50:12
问题 I'm reading this article and the section on the promise abstraction seems a little overly complicated to me. The following is given as an example: requestSomeData("http://example.com/foo") // returns a promise for the response .then(function(response){ // ‘then’ is used to provide a promise handler return JSON.parse(response.body); // parse the body }) // returns a promise for the parsed body .then(function(data){ return data.price; // get the price }) // returns a promise for the price .then

Level of Indirection solves every Problem

冷暖自知 提交于 2019-11-27 05:32:20
问题 What does the quote "Level of Indirection solves every Problem" mean in Computer Science? 回答1: Generally it means that by increasing the level of abstraction one can make the problem easier to understand/resolve. Be careful with your abstractions though, the full quote at least as I heard it is, "You can solve every problem with another level of indirection, except for the problem of too many levels of indirection". 回答2: From the book Beautiful Code: All problems in computer science can be

Does the Bridge Pattern decouples an abstraction from implementation?

泪湿孤枕 提交于 2019-11-27 01:36:20
问题 I learned Bridge pattern from different articles and I have implemented that as per my understanding . One thing that is confusing me is bridge pattern says BridgePattern decouples an abstraction from its implementation so that the two can vary independently what is meaning of this statement? Is implementation resides at in separate jar ? what is meaning of vary independently statement ? considering the provided journaldev article, elaborate the answer. Any help is greatly appreciated. 回答1:

When should I return the Interface and when the concrete class?

会有一股神秘感。 提交于 2019-11-26 21:08:49
问题 when programming in Java I practically always, just out of habit, write something like this: public List<String> foo() { return new ArrayList<String>(); } Most of the time without even thinking about it. Now, the question is: should I always specify the interface as the return type? Or is it advisable to use the actual implementation of the interface, and if so, under what circumstances? It is obvious that using the interface has a lot of advantages (that's why it's there). In most cases it

Using generics in abstract classes

痴心易碎 提交于 2019-11-26 20:35:27
问题 I'm working on an abstract class where the implementing class needs to implement a list of T. The problem is that this doesn't work: public class AbstractClass { public int Id { get; set; } public int Name { get; set; } public abstract List<T> Items { get; set; } } public class Container : AbstractClass { public List<Widgets> Items { get; set; } } I'm sure that there is an obvious answer that I'm missing, and I know that I can build an abstract base type to put in the list, but when I use my

Simple way to understand Encapsulation and Abstraction

别等时光非礼了梦想. 提交于 2019-11-26 19:30:35
Learning OOP concepts especially interested to understand Abstraction and Encapsulation in depth. Checked out the below already Abstraction VS Information Hiding VS Encapsulation difference between abstraction and encapsulation? I found very hard to understand those concepts with out a real and simple example class/code snippet. One of my colleagues said abstraction is nothing but creating abstract class and normal class that protects its member variable with scope is called Encapsulation. Is there a simple way I can understand and help others to understand what exactly they are, rather than

Why should I use a human readable file format?

江枫思渺然 提交于 2019-11-26 19:17:30
问题 Why should I use a human readable file format in preference to a binary one? Is there ever a situation when this isn't the case? EDIT: I did have this as an explanation when initially posting the question, but it's not so relevant now: When answering this question I wanted to refer the asker to a standard SO answer on why using a human readable file format is a good idea. Then I searched for one and couldn't find one. So here's the question 回答1: It depends The right answer is it depends. If