abstraction

How abstraction and encapsulation differ?

北城余情 提交于 2019-11-26 18:21:33
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 to the client of the object and Let’s say you have a method "CalculateSalary" in your Employee class,

Why are interfaces preferred to abstract classes?

我怕爱的太早我们不能终老 提交于 2019-11-26 15:13:48
问题 I recently attended an interview and they asked me the question "Why Interfaces are preferred over Abstract classes?" I tried giving a few answers like: We can get only one Extends functionality they are 100% Abstract Implementation is not hard-coded They asked me take any of the JDBC api that you use. "Why are they Interfaces?". Can I get a better answer for this? 回答1: That interview question reflects a certain belief of the person asking the question. I believe that the person is wrong, and

Simple way to understand Encapsulation and Abstraction

假如想象 提交于 2019-11-26 06:58:16
问题 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

What is the difference between an interface and a class, and why I should use an interface when I can implement the methods directly in the class?

筅森魡賤 提交于 2019-11-26 04:05:47
问题 I am aware that this is a very basic question, but an interviewer asked me in a very trick way and I was helpless :( I know only material or theoretical definition for an interface and also implemented it in many projects I worked on. But I really don\'t understand why and how is this useful. I also don\'t understand one thing in interface. i.e for example, we use conn.Dispose(); in finally block. But I don\'t see that class is implementing or inheriting IDisposable interface ( SqlConnection

Abstraction VS Information Hiding VS Encapsulation

烂漫一生 提交于 2019-11-26 00:26:30
问题 Can you tell me what is the difference between abstraction and information hiding in software development? I am confused. Abstraction hides detail implementation and information hiding abstracts whole details of something. Update: I found a good answer for these three concepts. See the separate answer below for several citations taken from there. 回答1: Go to the source! Grady Booch says (in Object Oriented Analysis and Design, page 49, second edition): Abstraction and encapsulation are

Difference between abstraction and encapsulation?

青春壹個敷衍的年華 提交于 2019-11-25 23:48:04
问题 What is the precise difference between encapsulation and abstraction? 回答1: Most answers here focus on OOP but encapsulation begins much earlier: Every function is an encapsulation ; in pseudocode: point x = { 1, 4 } point y = { 23, 42 } numeric d = distance(x, y) Here, distance encapsulates the calculation of the (Euclidean) distance between two points in a plane: it hides implementation details. This is encapsulation, pure and simple. Abstraction is the process of generalisation : taking a

Why use getters and setters/accessors?

╄→尐↘猪︶ㄣ 提交于 2019-11-25 22:52:01
问题 What\'s the advantage of using getters and setters - that only get and set - instead of simply using public fields for those variables? If getters and setters are ever doing more than just the simple get/set, I can figure this one out very quickly, but I\'m not 100% clear on how: public String foo; is any worse than: private String foo; public void setFoo(String foo) { this.foo = foo; } public String getFoo() { return foo; } Whereas the former takes a lot less boilerplate code. 回答1: There are