Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!

Sukumar Sat

Greenhorn
+ Follow
since Jan 07, 2021
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
1
Given in last 30 days
1
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Sukumar Sat

Tim Holloway wrote:Well, technically, all Inversion of Control (IoC) requires is that instead of going out and finding things (Locator Pattern), someone/thing injects those things in.

But it's a lot more flexible if the injectable things are abstract, as that makes them plug-replaceable.

One of my favorite examples along those lines is using an email interface. If you have a class that generates emails, injecting an email sender Interface means that you can test the generating class with a dummy email sender injected in, then inject the actual email sender when you are ready to go live. Thus sparing the world a lot of junk email.



Tim,

I thank you for your valueable efforts.
I am yet requesting for your precise comments.
Let me put my two questions in different way: -

Q#Question
1Can interface be used as variable/ field? If yes, please quote reference under which scenario? please give an example to illustrate
2Can interface be used as argument/ parameter? If yes, please quote reference under which scenario? please give an example to illustrate



With thanks,
Sukumar
5 days ago

Junilu Lacar wrote:

Sukumar Sat wrote:
I can rewrite code as following: -


You're "rewrite" doesn't work so there's really nothing to compare other than the original works and yours doesn't.



Please find below working and tested Java code rewritten for Original and for comparison: -



Output: https://imgur.com/a/ksOs7HS

5 days ago

Junilu Lacar wrote:

Sukumar Sat wrote:
I can rewrite code as following: -


You're "rewrite" doesn't work so there's really nothing to compare other than the original works and yours doesn't.




Please review that both codes (original and rework) would not run (throw error by Java compiler).

Experts from Java should be able to recognise it as a conceptual question, and not as a coding question.

My two questions are about Syntax and not about entire code.

I am waiting for Java experts.
5 days ago

Junilu Lacar wrote:The code was given as an example of the Dependency Inversion Principle, i.e. depend on abstractions instead of concrete implementations. An interface is an abstraction, so. that's why the field and the method parameter are using the interface type instead of any specific implementation type. This way, the program can use any implementation. If someone comes up with a different implementation of the EngineInterface in the future, you can easily use it without changing any of the code in the Car class.

On the other hand, if the Car class depended on a specific implementation instead, the program code will need to be modified if you want to use a different engine implementation in the future.



I can rewrite code as following: -




Please review that my two questions remain same, as what difference aforesid Code makes syntactically to below Code : -

5 days ago
I saw this first time and I am curious as how this happened?



Source: https://www.educative.io/edpresso/what-are-the-solid-principles-in-java
License: Creative Commons -Attribution -ShareAlike 4.0 (CC-BY-SA 4.0)

5 days ago

Tim Moores wrote:The Domain class has no particular purpose except to illustrate the concept of BiPredicate - it models an internet domain (like "google.com") along with a "goodness" score of that domain.

The filterBadDomain method simply applies a Bipredicate to a List of domains. it's shown in action several times in the code; did you get that to run now? That should be the first step in learning from this example, as it makes it much easier to understand what's going on. (Although the source code does actually show the output of each of the System.out.println statements.)



Tim,

Thank you again,

I have amended code and shared working code below with some questions, for which I need your help to understand.

I understood that in Java 8, BiPredicate is a functional interface, which accepts two arguments and returns a boolean

Please help me with answers to those Six requested questions asked in comments within below code.
Please give any Reference to elaborate my Learning.

1 week ago

Tim Moores wrote:Welcome to the Ranch.

Note this comment in the Domain class:

// getters , setters , toString

That means you need to add the usual getter and setter methods: setName, getName, setScore and getScore. (toString is not needed for this example.)



Tim,

Thank you,

Can you please help me by explaining class Domain and filterBadDomain method?

How it is helping entire program?

Sukumar
1 week ago
I was searching for BiPredicate examples.

I found it here 2. BiPredicate as function argument

But this code gave two compile time errors, which are attached herewith.

Though, comments are given along with code, but those comments are insufficient to understand flow of program

I request that any developer please help me with rectifying bugs as well as writing detailed comments after each line.
1 week ago