Questions tagged [abstraction]

Abstraction is a computer science concept in which an implementation is separated from its interface.

Abstraction is a computer science concept in which an implementation is separated from its interface. Abstraction allows an implementation to be modified without changing the interface, so that other code which relies on this interface does not have to be modified.

For instance, a function prototype in C would be considered the function's interface, and its definition is considered the implementation. The function definition can change (for instance, to improve performance or fix a bug), but as long as the function signature (as specified by the prototype) is the same, any code calling the function can remain the same.

1026 questions
-2
votes
1 answer

with initializing arrays from methods

So I have an abstract class, Player. Then I have classes, thePlayer, and Dealer, which extend Player. I have a method initHand, which is an array of BlackJackCard. in thePlayer and Dealer I call this method to assign to my own array to use. However,…
-2
votes
2 answers

How to handle 2 objects of 2 classes in the same way

I have 2 classes A and B with different members inside. In order to compare object of the same class I've overridden the hashCode() and equals() methods of both of them. Depending on some factors, I have to compare items in an ArrayList of A or…
Daniele Vitali
  • 3,684
  • 7
  • 43
  • 69
-3
votes
0 answers

How do I populate a 2d array of type TownCell when the TownCell constructor is dependent on the class that 2d array is in

So I have a class called Town and a class called TownCell. My Town constructor requires that I use a 2D array of type TownCell. This array is inside the Town class. I wish to randomly populate this 2D array. However, the constructor for TownCell has…
Sophie
  • 1
  • 2
-3
votes
0 answers

Is it fair to say that encapsulation is the enforcement of abstraction?

Let's say we have a function that parses an XML document. We don't want the user to know HOW the function works underneath the hood, so we hide the details away. That would be abstraction. But to make sure that this function remains abstraction, we…
Jules
  • 403
  • 2
  • 7
-3
votes
3 answers

What is significance of abstraction from an end user perspective

Recently I was asked a question in an interview that even if we are using abstract classes or interfaces in our code the end-user, who is most probably be clicking buttons on UI, won't be exposed to inner functionality. So even if we don't implement…
thealchemist
  • 341
  • 1
  • 12
-3
votes
2 answers

Why is this class better suited to be abstract instead of concrete?

Why is this Student class (a class which creates new student objects and assigns them unique ID's) better suited to be an abstract class rather than a concrete class? Each student object created is assigned it's own unique ID right, so why not just…
-3
votes
1 answer

How to properly use interfaces and data abstraction together in C++?

I'm fairly confident in C and Java and just started using C++, still getting used to the basics about best practices including data abstraction (which, as far as I understand, means proper header usage). I'd like to make a project that solves…
SakoDaemon
  • 904
  • 1
  • 6
  • 17
-3
votes
2 answers

Abstraction patterns in go

I have two interfaces. They are almost the same, the only difference is the Set method: type Cache1 interface { Set(key, value interface{}, ttl time.Duration) bool } type Cache2 interface { Set(key, value interface{}) bool } Any idea how…
Rudziankoŭ
  • 8,411
  • 10
  • 66
  • 146
-3
votes
1 answer

C++ Iterating with for loop and calling a function within it

So I've been following some tutorials on Udemy for C++ and so far it's been incredibly informative and clear however I'm a little stumped by how a for function is calling another function. So my first function is; EDIT I've included use namespace…
Munerz
  • 682
  • 1
  • 8
  • 22
-3
votes
2 answers

abstraction can be done without inheritance? java

Is abstraction possible without inheritance? This is my code abstract class whatever { abstract void disp1(); abstract void disp2(); abstract void disp3(); } class what { void disp1() { System.out.println("This is…
-3
votes
2 answers

Reasons to use generic List over List of object

I know two reason to use generic List over List of objects. To restrict what type of objects can be inserted into the List List stringObjects = Arrays.asList("a",new Integer(5)); List genericStrings = Arrays.asList("a",new…
Borislav Stoilov
  • 1,684
  • 1
  • 13
  • 28
-3
votes
1 answer

How to return child class object intead of base class object

abstract class B { } public abstract class A { public abstract B createBInstance(); } public class C extends A { @Override public D createBInstance() { return new D; } } where public class D extends B { } This give a compiler…
Malinda
  • 308
  • 1
  • 11
-3
votes
2 answers

In c# Parent class object initialized by child class instance

I have seen many examples on the concepts of inheritance, abstraction and polymorphism where an object of a base class is being initialized by a child class like below: BaseClass obj1 = new ChildClass(); Most of the examples only used unreal and…
-3
votes
1 answer

Passing Data from UI layer to Business

class MyProjectBusiness { // Interaction (read Write)) with DB } class MyProjectUI { // this class interacts with Business Logic } class MyProjectUIControls { // These are just User controls consumed by UI, No Interaction to Business…
user3745020
  • 71
  • 1
  • 7
-3
votes
2 answers

How can a sub-class access not-static members of an abstract class?

I am a new-bee to Java. I know, even a sub-class can not refer a non-static member of a base class directly. like, class BaseClass { int id; public void testMethod() { System.out.println("Hello"); } } public class Test1 extends…
Touhid K.
  • 321
  • 1
  • 4
  • 20
1 2 3
68
69