• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

OOP: About object's methods  RSS feed

 
Ranch Foreman
Posts: 134
5
BSD Debian Open BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A colleague lent me a book, a really very very nice book that can be used  from beginners too  (as an extra other than their text book).
Holger use live-code examples from the Eclipse IDE and useful tips on use efficiently that IDE. The tips are strictly connected with the
topics covered  
[url=https://www.goodreads.com/book/show/26263740-how-to-use-objects?ac=1&from_search=true]How to Use Objects
Code and Concepts
by Holger Gast[/url]



Reused Functionality
One of the main objectives in OOP is code reuse and our code reside mainly in methods included in classes and in ultimate analysis
in objects.
Methods represents the behaviour of our objects and contain all the necessary logic(operations on the fields) to solve a given problem.
Every method  implement a functionality.
The set of methods (except usually a small part of private helper methods) of an object is exported as an interface(a service) to be
used from other (client) objects that possibly requires that service.
Was not bad at all if we might reuse that functionality/code not only on the problem for which we written the method but also for similar
problems that we might meet in other parts in a large project or also in future without either have to reinvent the wheel every time or
use copy-past.
First of all we have to decide where to put the method's reusable code in a manner that can be accessible as widely as possible
We've different options let's explore them:

Reuse Within a Class
That's a degenerate /trivial  case in which a method is used into the same class that it is declared. In that case the method's accessibility
modifier have to be  private, or protected (if have to be available within the inheritance hierarchy).

Reuse Through Inheritance
Inheritance is one of the three pillars (encapsulation, inheritance, polymorphism) of OO  and was pointed on code reuse since the early
days.
In that case the method's accessibility modifier have to be at least protected(if the method is defined in a different package than the
base class). 
When devs need new functionality they would simply extend an just existing  parent class and code only the specific part of the newly
defined class
Theoretically seems straightforward but practically is not trivial  identify reusable, general services/methods; that's a matter of
(moreover) experience other than careful planning and  forethought

Furthermore all that generality/reusability not comes for free  is costly in terms of effort  and difficulties
Suppose we have a complex method in a class that was never intended for reuse but the code has all the goodies, is perfect and we
want reuse it  
We can do that if we move the code to a superclass
To recap we apply the generality principle first we construct the methods and then put our methods to superclasses.
The task is daunting but thanks to  agile software development's
motto “do the simplest thing that could possibly work” we can accomplish it. If later on that solution turns out to be no longer good
enough for a newer problem we can refactor it.

Reuse Through Separate Objects
Reuse Through Inheritance has it's drawbacks i.e.
fills the single available superclass slot and
increases the class's coupling in the class hierarchy. Mean modifying a base class can easily break the subclasses, so you may not
be able to adapt the class to new challenges.

Here's another way to get code reuse by extracting the functionality into a  small, self-contained completely separate object that acts
as a container for the desired  functionality.

Reuse Through Static Methods
That's a particular and relatively rare case, in which the functionality to be reused does not relate to any hidden state in some object.
In principle, however, static methods are not properly object-oriented:
They do not belong to objects, but rather to classes.
If some later extension of the functionality happens to require fields after all, you have to rearrange your software quite severely, by
passing along suitable object references
.

NOTE:
A fundamental conceptual reason for avoiding static is that classes in Java are second-class citizens:
The objects accessible through .class or getClass() do not exhibit dynamic dispatching, they cannot implement interfaces, and so on.
In contrast, Smalltalk starts from the premise that “everything is an object”—even the classes.
The question follows: What is the class of a class?
It is a meta-class, which defines the (static) methods of the class, and inheritance on classes induces inheritance on their meta-classes
—in consequence, one can override static methods.
The flexibility ends, however, one step further: The class of all meta-classes is MetaClass, a fixed entity, just like Class in Java.
 
Harry Kar
Ranch Foreman
Posts: 134
5
BSD Debian Open BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dunno why but some links look weird(looked ok in preview),-- I smell a bug here --  and 2 pics was not loaded(maybe descriptions are required?) i try to reload  hope well
 
Marshal
Posts: 60136
188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Harry Kar wrote:A colleague lent me a book, a really very very nice book that can be used  from beginners too  (as an extra other than their text book). Holger use live-code examples from the Eclipse IDE and useful tips on use efficiently that IDE. The tips are connected with the topics covered  
[url=https://www.goodreads.com/book/show/26263740-how-to-use-objects?ac=1&from_search=true]How to Use Objects
Code and Concepts
by Holger Gast[/url] . . . Dunno why but some links look weird(looked ok in preview)

I think the problem was that you had the “Disable HTML...” box ticked when you posted. I quoted part of your post and the links lok all right.
The material is too difficult for the Beginning forum, so I shall move you. Unfortunately, the excerpt is too long to avoid copyright problems, so I am going to have to ask you to remove it.
 
Harry Kar
Ranch Foreman
Posts: 134
5
BSD Debian Open BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:

Harry Kar wrote:A colleague lent me a book, a really very very nice book that can be used  from beginners too  (as an extra other than their text book). Holger use live-code examples from the Eclipse IDE and useful tips on use efficiently that IDE. The tips are connected with the topics covered  
[url=https://www.goodreads.com/book/show/26263740-how-to-use-objects?ac=1&from_search=true]How to Use Objects
Code and Concepts
by Holger Gast[/url] . . . Dunno why but some links look weird(looked ok in preview)

I think the problem was that you had the “Disable HTML...” box ticked when you posted. I quoted part of your post and the links lok all right.
The material is too difficult for the Beginning forum, so I shall move you. Unfortunately, the excerpt is too long to avoid copyright problems, so I am going to have to ask you to remove it.



I reformulate the first post it with my own words and from the second post i deleted the screenshots too hope that's enough; if still there is any problem tell me or scrap that thread out .
Sorry about that i had another intentions and abstract completely about  copyright issues 
 
Campbell Ritchie
Marshal
Posts: 60136
188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for thee corrections. Oddly enough the links which looked all right earlier have reverted to plain text. Don't know why.
 
Campbell Ritchie
Marshal
Posts: 60136
188
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Other people have been discussing the problem and it would appear to be to do with the [url=...] part not being on the same line as the description.
 
Harry Kar
Ranch Foreman
Posts: 134
5
BSD Debian Open BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Other people have been discussing the problem and it would appear to be to do with the [url=...] part not being on the same line as the description.


Slmost the same tell me Knute too few days ago; Now  during corrections i swear i have not touched the books's link and as i can remember the link appeared ok(in browse mode) till the last time i accessed the post for correction. As i said seems to me as a bug .
Right now i notice  Disable HTML is unticked but i don't touched it (i notice however that option as ever ticked if i am not wrong). What exactly is the meaning of that option?
Staff note (Ganesh Patekar):

Please go through https://coderanch.com/t/698775/Url-weird#3279224 Enabling HTML option makes system recognize HTML tags in the post and display contents accordingly else displays as simple text.

 
Campbell Ritchie
Marshal
Posts: 60136
188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Harry Kar wrote:. . . Disable HTML is unticked but i don't touched it (i notice however that option as ever ticked if i am not wrong). What exactly is the meaning of that option?

Not sure, but I unticked it on my first post, so that has presumably unticked it for all subsequent posts. I had the same experience that the links appeared correct first time and went wrong later.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!