In the previous article, we used the simplest method to implement the bubble sort method. It is now implemented using the abstract class method.
Abstract classes Implement Bubble Sorting:
First, define an abstract class. The function of this abstract class is to implement the Bubble sorting method. The code is:
Using
The problem that this paper solves
What is abstract class
Application Scenarios for abstract classes
Can interfaces be implemented in a method?
The difference between an interface and an abstract class
1 What is abstract classWhen declaring a keyword abstr
Abstract METHODS in abstract classes cannot be final, but they can be compiled by adding final before non-Abstract METHODS because abstract and final are mutually exclusive. The former is used for inheritance, and the latter is not allowed for inheritance.
Abstract METHODS
Abstract method: A method that does not have a method body in a class is an abstract method.Abstract classes: Classes that contain abstract methods are called abstract classes.||||||||| Abstract classes cannot be instantiated (new)Why use
(such as the Java Interpreter) runs a method, it first finds the method in the current class, then finds it in its superclass, and always looks up at the class level until the method is foundExamples of final methods:Class parent{public Parent () { }//constructor method final int getpi () {return math.pi;}//Finalization method}Description: GETPI () is a finalization method declared with the final modifier and cannot be overloaded in subclasses2. Abstr
This article mainly introduces the problem analysis of abstract and abstract methods in PHP, and some friends need to refer to it. In an object-oriented (OOP) language, a class can have one or more subclasses, and each class has at least one interface that the public method accesses as external code. and abstract methods are introduced to facilitate inheritance
The relationship between abstract classes and abstract methodsClasses with abstract methods must be abstract classes; Abstract classes do not necessarily have abstract methodsWhen subclasses inherit
Object-oriented programs are constructed by hierarchical structure of classes. In a single inheritance language such as PHP, the inheritance of a class is tree-like. A root class has one or more subclasses, and then inherits one or more next-level subclasses from each subclass. Of course, there may be multiple root classes that can be used to implement different functions. In a well-designed system, each root class should have a useful interface that can be used by the application code. If our a
we conclude that the employee class should not be instantiated.
How do I ensure that a class is not instantiated? Just declare the class as an abstract class. You can use the abstract keyword as follows:
Public abstract class Employee {
private String name;
private double salary;
TBC
}
When an employee class is declared
Abstract class and abstract methods are decorated.A class that contains an abstract method can only be defined as an abstract class, but there is no abstract method in an abstract class.There is no method body for
Features of the Java abstract class:* Abstract classes cannot be instantiated* Subclass inherits Abstract class and instantiates subclass* Subclasses inherit abstract classes has penny must implement abstract methods in abstract c
Python interfaceIn Python, there are two types of interfaces, one is the API interface that is accessed through a URL.One is an interface to an objectConstructing interfacesclassIjiekou:"""Defining a constraint interface""" defF1 (Self,nid):RaiseException ('All classes inheriting this interface class must implement (present) the F1 method')classoduixiang1 (Ijiekou):"""The F1 method is implemented by the inheriting interface.""" defF1 (Self, nid):Print(NID)classoduixiang2 (Ijiekou):"""The i
PHP abstract method and abstract class Abstracts keywordThe abstract keyword is used to define abstraction methods and abstract classes.
Abstract methods
Abstract methods are methods that do not have a method body, specifically
1. Why do I need abstract classes? How do I define an abstract class?* is a template mode. Abstract classes provide a generic template for all subclasses, which can be extended on the basis of this template.* By abstract class, you can avoid the arbitrariness of sub-class design. Through
/* Abstract design and abstract methods using abstract adornments and methods that have no method body, called abstract methods *//*//graphics classgraph{publicdouble getares () {return0.0; }}//round Classcircleextendsgraph{privateinteger r;circle (Integerr) { this.r=r;}//Area publicdoublegetares () { return3.14*r*r;}
GOF The book "Design Pattern" describes the abstract factory pattern:
Provides an interface for creating a set of related or interdependent objects, and does not need to specify their specific classes.
The general meaning is that when we create these objects, we do not need to specify their specific classes whose objects are instantiated by the factory object. The following is an example of the book "Design Patterns Explained", where the display and
JAVA interface and abstract class, JAVA interface abstract class
For object-oriented programming, abstraction is one of its major features. In Java, OOP abstraction can be embodied in two forms: interfaces and abstract classes.
I. abstract class
If a class contains an abstract
Design | example | source code
Using System;
Namespace Design_pattern
{
public class Computer
{
Private RAM RAM;
Private CPU CPU;
Public Computer (RAM ram,cpu CPU)
{
This. Ram =ram;
This. Cpu =cpu;
Console. WriteLine ("A Computer is composed!" +this. Ram + "" +this. CPU);
}
}
Public abstract class RAM
{
Public abstract Computer Composeacomputer (CPU CPU);
}
Public a
The problem with factory method mode is that class creation relies on the factory class, that is, if you want to expand the program, the factory class must be modified, which violates the closure principle, so from the design point of view, there are certain problems, how to solve? Use the abstract factory pattern to create multiple factory classes so that once you need to add new functionality, you can add new factory classes directly, without having
The difference between an interface and an abstract class. What is the difference between an interface and an abstract class? what is the basis for using an interface and an abstract class? The concepts of interfaces and abstract classes are different. Differences between interfaces and
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.