Use eclipse to create a library management system (1) ----- build the architecture

Table of contents

mind Mapping:

Creation of library management system:

The first step: build the framework ------- users

The second step: build the framework------by the user

The third step: operation method

Step 4: main function


mind Mapping:

 Foreword:

Yesterday I learned how to use Java language to write a library management system, so I wrote a blog today as a small note to consolidate what I have learned! The blogger is also just learning, maybe the writing is not very clear, very clear..., I hope everyone understands!

Creation of library management system:

The first step: build the framework ------- users

This process is the easiest, as long as you clearly know who your library management system is targeting! For example, what I wrote, the objects I face are users: AdminUser and NormalUser, and the objects used: Book and Booklist.

So my first step was to create these classes:

The first one: User (parent class)

package User;

public  class User {
 
  protected String name;
  public User(String name) {
	// TODO Auto-generated constructor stub
	  this.name = name;
}
	
}

Second: AdminUser (subclass)

package User;

public class AdminUser extends User{
	public AdminUser(String name) {
		// TODO Auto-generated constructor stub
		super(name);//先帮父类构造
		this.name = name;//再自己构造
	}

}

The third: NormalUser (subclass)

package User;

public class NormalUser extends User{
	public NormalUser(String name) {
		// TODO Auto-generated constructor stub
		super(name);
		this.name = name;
	}

}

illustrate:

1. These three classes are in the same package

2. As for why create an additional parent class User? It is because it is convenient for downward transformation!  After all, two subclasses cannot be unified when they are called, but it is easy to unify by adding a parent class!

The second step: build the framework------by the user

Who are the users in this project? Without a doubt our books and bookshelves! Because what you want to borrow is a book, and the book is on the shelf. If you want to move the book, you will naturally move the bookshelf! ! ! So our operation object is determined.

So my second step created these two objects:

The first one: Book class

package Library;

public class Book {
	private String name;
	private String type;
	private String author;
	private int price;
	private boolean isBorrow;
	public Book( String name,String type,String author, int price) {
		this.name = name;
		this.type = type;
		this.author = author;
		this.price = price;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public String getAuthor() {
		return author;
	}
	public void setAuthor(String author) {
		this.author = author;
	}
	public int getPrice() {
		return price;
	}
	public void setPrice(int price) {
		this.price = price;
	}
	public boolean isBorrow() {
		return isBorrow;
	}
	public void setBorrow(boolean isBorrow) {
		this.isBorrow = isBorrow;
	}
	
	

}

 The second class: Booklist

package Library;

public class Booklist {
	Book[]books = new Book[10];//创建一个Book类型的数组来当书架
	public Booklist(Book[]books) {//构造方法初始化数组
		// TODO Auto-generated constructor stub
		books[0] = new Book("三国演义", "古典小说", "罗贯中", 66);
		books[1] = new Book("水浒传", "古典小说","施耐庵", 55);
		books[2] = new Book("三体", "科幻小说", "刘慈欣", 88);		
	}
	

}

illustrate:

1. These two classes are also in the same package

2. Using the private modifier in the Book class can better encapsulate and ensure that variables such as name and author cannot be changed at will. It can only be obtained and changed through the get and set methods.

3. The reason why isBorrow is not initialized in the constructor is because it defaults to false. At the beginning, the books in our bookshelf were not borrowed, so isBorrow is false.

The third step: operation method

The function of the operation method is varied, that is to say, it is polymorphic. So we can think about how to achieve polymorphism in a polymorphic way.

Interface: IOperation

package Operation;

import Library.Booklist;

public interface IOperation {
	public void work(Booklist booklist) ;//接口内的方法,操作的对象是Booklist。
	

}

 The second class: AddOperation

package Operation;

import Library.Booklist;

public class AddOperation implements IOperation{
	public void work(Booklist booklist) {//重写方法,使这个方法变为Addoperation的方法
		System.out.println("添加图书!");
	}

}

The second class: DelOperation

package Operation;

import Library.Booklist;

public class DelOperation implements IOperation {
	public void work(Booklist booklist) {//重写方法,使work方法变成DelOperation的方法
		System.out.println("删除图书!");
	}

}

The third class: FindOperation

package Operation;

import Library.Booklist;

public class FindOperation implements IOperation {
   public void work(Booklist booklist){//重写work方法使之成为FindOperation的方法
	   System.out.println("查阅图书!");
   }
}

The fourth class: DisplayOperation

package Operation;

import Library.Booklist;

public class DisplayOperation implements IOperation {
public void work(Booklist booklist) {
	System.out.println("显示图书!");
}
}

The fifth class: isBorrowOperation

package Operation;

import Library.Booklist;

public class isBorrowOperation implements IOperation {
public void work(Booklist booklist) {
	System.out.println("借阅图书!");
}
}

The sixth class: returnOperation

package Operation;

import Library.Booklist;

public class returnOperation implements IOperation{
	public void work(Booklist booklist) {
		System.out.println("归还图书!");
	}

}

illustrate:

1. The interface here is to achieve polymorphism and facilitate future calls.

2. The methods in the interface can only be defined but not written.

3. Each method that inherits the interface must rewrite the method in the interface to form its own method

4. These classes and interfaces are all in the same package

Step 4: main function

Just like I used to write a small game in C language with a test.c source file to implement the game logic, implementing a library management system in Java also requires a separate main function to implement the logic of the library management system!

Create the main function in the same package as User:

package User;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}

 Conclusion:

Now we have completed the framework of the library management system! The next thing to do is to implement the logic of the library management system!

おすすめ

転載: blog.csdn.net/qq_41934502/article/details/130460867