Question About the Concept of Abstracts in Java
#1
I have been consulting some texts regarding the purposes of abstracts when used Java.

As I understand it, abstracts are used when different subclasses have different functionalities for the same methods in the superclass.

What would happen if I didn't use abstraction? For example, what would happen if I just use the same name of the methods that are different in behaviour instead of applying such a concept? Wouldn't that be the same thing?

EDIT: To come to think of it, I think I know the answer to my own question: it could be to make the code look clean. If the usperclass has code by default, it could look messy even if overriding it works.

What do you think?

EDIT: Actually, if the abstract methods don't become redefined, I believe the compiler will tell you that. Is the reason that the mechanism of the compiler will remind you, accounting for human error?
Reply
#2
Yeah, you are correct, as of my understanding, we can define common core functionalities in abstract class which will be the outer layer of a service.
So, we need not rethink the same solution every time. Just we need to implement the process as per the requirement.

ex:
ListObjectAbstract is an abstract class. (list, pagination, sort, search)
Object defines any entity in your world. (User, Comments, Posts) (In Social Media World)
Users, Comments, Posts Object extends ListObjactAbstract Class.
Reply
#3
Abstraction allows you to define a blueprint (an abstract class) that outlines the structure and methods that subclasses must implement. It brings a sense of organization and clarity to the code. Without abstraction, each subclass might implement its version of the method without a clear indication of a mandatory implementation, which could lead to a lack of coherence and consistency in your codebase.
Reply
#4
Late responses, but I suppose I should be so luck to have any response at all.

Thanks, and keep on coming!

EDIT: samui, I am on the practical side than the theory, so forgive me if I am specific on my work and not the concept in general, but by my understand of abstraction, I'll have to write the definition of the function on each class anyways, so what is the point?
Reply
#5
If you do not use abstraction, code may become less organized and more challenging to maintain. It may lack the clear expression of relationships between classes, potentially leading to decreased scalability and readability.
Thanks
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Java Course Materials RobertX 6 9,557 Sep 05, 2024, 02:36 am
Last Post: samui
  how can i learn to use Java efficiently Blue_Bon 10 11,365 Feb 26, 2024, 08:41 am
Last Post: RobertX
  Need help with statistics interview question Avantika_Sharmaa24 2 9,173 Aug 25, 2023, 10:19 am
Last Post: gulshan212
  [Release] OfflineBay v2 - Open source and No more Java dependency techtac 55 327,271 Apr 01, 2022, 13:42 pm
Last Post: UnknownIdot
  Regarding to Purpose for .class files in Java ankitdixit 1 11,583 Mar 10, 2022, 14:26 pm
Last Post: RobertX



Users browsing this thread: 2 Guest(s)