Java 8 introduced the concept of default implementation for interfaces? Isn't this violating Open Closed Principle, since based on the example on https://docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html, it seems like you can always open up interface to add new features?
Open Closed Principle Vs Default Implementation
443 Views Asked by P. Sharma At
2
There are 2 best solutions below
0
istepaniuk
On
In Object-Oriented Software Construction (Meyer, Bertrand 1988) The Open-Closed principle is introduced:
"software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification".
At any point it says that an explicit interface is required (and it's not). Moreover, it clearly says that this also applies to functions, or even whole modules.
Object-oriented code can violate this principle... or not, independently of the syntactical constructions that it employs. It might be true that some particular constructions "invite" OCP violations, but if we are threading this fine, abstract classes would fall in the same bucket.
Related Questions in JAVA-8
- Java control panel glitching or becomes yellowish
- Uneven Load Distribution in Kubernetes Pods with Multithreaded Execution using fork join pool
- test result: Error. Program `sh' timed out (timeout set to 480000ms, elapsed time including timeout handling was 480002ms)
- java.net.ConnectException: Connection timed out: no further information Java to SOAP
- Java Stream, Need to update list of list objects
- Setting up different Java class fields value by a single value on some counter value
- feign client Spring boot
- `TYPE_USE` vs `TYPE` vs `TYPE_PARAMETER` annotations
- Error faced in trying to install Java 8 on Raspberry Pi 4B
- Grouping by multiple fields and counting using in Java 8
- How to customize mention notifications in liferay 7.3.5
- Without _JAVA_OPTIONS and JAVA_TOOL_OPTIONS, whether LeanFT will work or not?
- How to build a CriteriaQuery from SQL query
- From a string I am manually setting the date and time in calendar, for the other days it is working fine but for 28 and 29 Feb it is setting wrong val
- Sort strings containing numbers, chars and ponctuations in ”human readable order”
Related Questions in ARCHITECTURE
- Where to store secret token for an embeddable web widget?
- Separation of Students and Users in NestJS Microservice architecture
- What's the right ZMQ architecture for my scenario?
- Javers in microservice architecture
- How to prevent users from creating custom client apps?
- How to manage different repositories for different clients with the same project?
- Adding users file storage feature to my application
- Transform Load pipeline for a logs system: Apache Airflow or Kafka Connect?
- Shoulld I decode JWT only on auth server?
- How to stored last ~1500 events in Sorted Set in Redis
- Should data be standardized on the backend or the client (front-end, mobile app)?
- Can I treat CNN channels separately to make placement predictions?
- How to handle sync distributed transaction in microservices?
- Database design, authentication and authorization in a microservices ticketing system
- Is there any example or design of a queue system in microservices?
Related Questions in OPEN-CLOSED-PRINCIPLE
- I cannot build an Expression Tree Node that follows the Open/Close Principle
- what is the correct way to implement open-closed principle in C#?
- How to implement the Open-Closed Principle in error handling for new error types?
- deploying application to Openshift using jenkins DSL using private repositories
- Open closed principle implementation python
- Understanding the Open/Closed principle - do we have a counter-example
- Best Practice Open Close Principle
- I know we can't call an extension method with the same name. But what are the other ways to achieve this?
- Workbook_Open() execution for hidding / showing Sheets at Excel startup
- How can I make type environments for an expression to satisfy specific conditions?
- Open-Closed Principle in Python OOD
- Open-Closed Priciple: is this rephrasing correct?
- Open/Closed Principle - How to integrate the principle with this code?
- How do I implement the open-close principle?
- Open close principle and Collective ownership. Extreme Programming
Related Questions in DEFAULT-METHOD
- default method executed instead of implementation
- Java 17: MenuIterator is not abstract and does not override abstract method remove() in java.util.Iterator
- Override Object methods inside interface using default methods- Misleading error
- VerifyError on Kitkat when code explicitly calls a default method
- How can I write a junit test case for default methods of interface with zero lines of code
- can abstract method do System.out.println?
- Selecting default implementation from indirectly inherited Interface not working
- Why is interface default method shadowed by parent private method?
- Class inheriting same method from two different interfaces and a single default implementation won't compile
- What is the point of the Functor -> Applicative -> Monad hierarchy
- OpenAPI generator returns 501 for implemented method
- Is it possible to implement native methods in interfaces?
- Override DefaultGroovyMethods method
- cannot call default method of parent interface using super
- Why, after compiling an interface, "default" method modifier is gone from "javap -v"?
Related Questions in DEFAULT-IMPLEMENTATION
- Default implementation for indexer
- What does it mean to define a default interface implementation as 'virtual'?
- android - kotlin differences between Normal class and data Class of methods default implementations
- Can the interface method with default implementation be implemented implicitly in a class?
- C# How to reference default interface implementation in implementer class
- C# how to add a default implementation to an interface which is overriding another interface
- Rust calling default implementation of function in specialized version
- helper function for default interface method
- C# 8.0 - Can't use default interface implementations
- Why does the compiler not see the default code in a protocol?
- Implementation of `first` in Arrow library
- What does 'impl MyTrait' do without 'for MyStruct' in Rust?
- Why were default methods included interfaces in Java 8 instead of adding additional interfaces to the Collection Framework?
- Trouble with Swift Protocols, associatedtypes, Self and default implementations
- Can compiler do a default implementation's inlining of the trait's method?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Software can be written using the default methods in interfaces and at the same time comply to the open-closed principle or use the default method in interfaces and violate the open-closed principle.
The Open-Closed principle is a design/architecture principle, and it is up to the programmer to follow the principle when designing and programming. The Java language cannot enforce its usage.
Since the Open Closed principle is not enforced by the Java language, it is possible to write a set of classes that violate or adhere to the open-closed principle using JDK 1.0 (the first version of Java) and only the JDK 1.0 set of language features. It is also possible to violate or adhere to the principle when using the interface default methods in interfaces or any of the latest features of Java. Adherence to the Open-Closed principle depends on what is written and how it is written. Java is just a language that you need to express the concepts in.