Java ~ Class, abstract class and interface, java Abstract class Interface
Recently, I was fascinated by the world of java, hoping to refactor my lind to a java version. Although I encountered some minor problems, I also solved them,Knowledge needs to be accumulated, and programmers need a pursuit!
Similar to C #, this class only removes the attribute concept and uses methods to operate specified fields.
package lind.Test;public class User extends Entity { public User(int id, String name) { super(1); this.name = name; } private String name; /** * @return the name */ public String getName() { return name; } /** * @param name * the name to set */ public void setName(String name) { this.name = name; }}
Abstract classes are a set of types. Some methods and fields are exposed for use by subclasses.
Package lind. test;/*** Entity ** @ author Administrator **/public abstract class Entity {public Entity (int id) {this. setId (id);}/*** @ return the id */public int getId () {return Id ;} /*** @ param id * the id to set */public void setId (int id) {Id = id;} private int Id ;}
The three interfaces specify the actions of a group of operations, such as warehouse CURD operations. They may publicly add, delete, modify, query, and other methods.
Package lind. repository; import java. util. arrayList; import java. util. function. predicate; public interface IRepository <T> {/*** add ** @ param entity */void Insert (T entity ); /*** Update ** @ param entity */void Update (T entity);/*** Delete ** @ param entity */void Delete (T entity ); /*** return list ** @ return */ArrayList <Object> GetModel (Predicate <T> predicate); ArrayList <Object> GetModel ();}
The four generic classes and generic interfaces are not as flexible as Csharp. during use, you must note that, of course, they have the same meaning and are mainly used to abstract and replace a class of functions, during implementation, you can directly transfer the corresponding type. Generally, our warehousing objects, such as user warehousing, can inherit a generic warehousing class, as shown below:
Package lind. Test; // public class UserDao extends JdbcDaoSupport <User> {}
5. After a non-generic class inherits the generic class, the name of the generic class is output.
This is a small trick, mainly to get the type in the generic class. It should be noted that there must be a non-generic class to inherit it and instantiate it, this type can be parsed. This is indeed not comparable to Csharp.
Thank you for your patience. Next time we will introduce the Hash table!